2017-05-04 100 views
7

android項目在Samsung S7 API 24,Nexus 6 API 24,API 23 Emulator,Pixel API 23和Galaxy Note 23 API仿真器上運行時沒有問題。android ormlite Samsung S4 API上的NoClassDefFoundError 21

當我在API 22或21的設備或模擬器上運行它時,第一次啓動App時引發以下異常。

05-04 11:48:25.045 10463-10463/com.xyz.abc E/AndroidRuntime: FATAL EXCEPTION: main 
      Process: com.xyz.abc, PID: 10463 
                   java.lang.NoClassDefFoundError: com.xyz.abc.database.helper.AbcDatabaseHelper 
         at com.xyz.abc.database.daos.UserRecordDao.<init>(UserRecordDao.java:32) 
         at com.xyz.abc.AbcApplication.onCreate(AbcApplication.java:148) 
         at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020) 
         at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5113) 
         at android.app.ActivityThread.access$1600(ActivityThread.java:177) 
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509) 
         at android.os.Handler.dispatchMessage(Handler.java:102) 
         at android.os.Looper.loop(Looper.java:145) 
         at android.app.ActivityThread.main(ActivityThread.java:5942) 
         at java.lang.reflect.Method.invoke(Native Method) 
         at java.lang.reflect.Method.invoke(Method.java:372) 
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 

爲什麼以及如何解決?

下面是的build.gradle

apply plugin: 'com.android.application' 

repositories { 
maven { url "https://jitpack.io" } 
} 

android { 
compileSdkVersion 25 

buildToolsVersion '25.0.3' 

defaultConfig { 
    applicationId "com.xyz.abc" 
    minSdkVersion 21 
    targetSdkVersion 22 
    versionCode Integer.parseInt(project.VERSION_CODE) 
    versionName project.VERSION_NAME 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

    multiDexEnabled false 
} 

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
    debug { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 

dexOptions { 
    preDexLibraries = false 
    javaMaxHeapSize "2g" 
} 

aaptOptions { 
    cruncherEnabled = false 
} 

packagingOptions { 

    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/NOTICE.txt' 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/NOTICE' 
    exclude 'META-INF/DEPENDENCIES' 
    exclude 'META-INF/DEPENDENCIES.txt' 
} 
} 

dependencies { 

// Required -- JUnit 4 framework 
// Optional -- Mockito framework 
compile fileTree(include: ['*.jar'], dir: 'libs') 
compile files('libs/aws/aws-android-sdk-cognito-2.1.10.jar') 
compile files('libs/aws/aws-android-sdk-core-2.1.10.jar') 
compile files('libs/aws/aws-android-sdk-s3-2.1.10.jar') 
compile('com.google.maps.android:android-maps-utils:0.4+') { 
    exclude group: "com.google.android.gms" 
} 
compile 'com.j256.ormlite:ormlite-android:4.48' 
compile 'com.marshalchen.ultimaterecyclerview:library:0.7.2' 
compile 'com.github.bumptech.glide:glide:3.7.0' 
compile 'com.android.support:appcompat-v7:25.3.1' 
compile 'com.android.support:design:25.3.1' 
compile 'com.android.support:support-v4:25.3.1' 
compile 'com.android.support:recyclerview-v7:25.3.1' 
compile 'com.jakewharton:butterknife:7.0.1' 
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.+' 
compile 'com.ogaclejapan.smarttablayout:library:[email protected]' 
compile 'com.ogaclejapan.smarttablayout:utils-v4:[email protected]' 
compile 'com.github.ppamorim:dragger:1.2' 
compile 'com.github.ksoichiro:android-observablescrollview:1.5.1' 
compile 'com.mixpanel.android:mixpanel-android:4.+' 
compile 'com.wdullaer:materialdatetimepicker:3.1.3' 
compile 'de.hdodenhof:circleimageview:2.1.0' 
compile 'com.github.frank-zhu:pullzoomview:1.0.0' 
compile 'com.github.techery:properratingbar:0.0.5' 
compile 'se.emilsjolander:stickylistheaders:2.7.0' 
compile 'com.google.android.gms:play-services:10.0.1' 
testCompile 'junit:junit:4.12' 
testCompile 'org.mockito:mockito-core:1.10.19' 
} 


apply plugin: 'com.google.gms.google-services' 

註銷運行它放在API 22

05-08 21:18:33.431 4597-4597/? E/libprocessgroup: failed to make and chown /acct/uid_10059: Read-only file system 
05-08 21:18:33.431 4597-4597/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT? 
05-08 21:18:33.432 4597-4597/? I/art: Not late-enabling -Xcheck:jni (already on) 
05-08 21:18:33.471 4597-4597/com.xyz.abc W/ResourcesManager: Asset path '/system/framework/com.google.android.maps.jar' does not exist or contains no resources. 
05-08 21:18:34.038 4597-4625/com.xyz.abc W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found. 
05-08 21:18:34.051 4597-4625/com.xyz.abc W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found. 
05-08 21:18:34.062 4597-4597/com.xyz.abc W/InstanceID/Rpc: Found 10007 
05-08 21:18:34.063 4597-4625/com.xyz.abc W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources. 
05-08 21:18:34.065 4597-4625/com.xyz.abc W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources. 
05-08 21:18:34.096 4597-4597/com.xyz.abc I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0 
05-08 21:18:34.096 4597-4597/com.xyz.abc I/DynamiteModule: Selected local version of com.google.android.gms.flags 
05-08 21:18:34.109 4597-4597/com.xyz.abc W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found. 
05-08 21:18:34.113 4597-4597/com.xyz.abc I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:4 
05-08 21:18:34.113 4597-4597/com.xyz.abc I/DynamiteModule: Selected remote version of com.google.android.gms.crash, version >= 4 
05-08 21:18:34.125 4597-4597/com.xyz.abc I/FirebaseCrashApiImpl: FirebaseCrashApiImpl created by ClassLoader p[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000003/DynamiteModulesC_GmsCore_prodlmp_alldpi_release.apk"], 

nativeLibraryDirectories=[/vendor/lib, /system/lib]]] 
05-08 21:18:34.138 4597-4597/com.xyz.abc I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0 
05-08 21:18:34.138 4597-4597/com.xyz.abc I/DynamiteModule: Selected local version of com.google.android.gms.flags 
05-08 21:18:34.144 4597-4597/com.xyz.abc W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found. 
05-08 21:18:34.182 4597-4597/com.xyz.abc I/FA: App measurement is starting up, version: 10084 
05-08 21:18:34.182 4597-4597/com.xyz.abc I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE 
05-08 21:18:34.182 4597-4597/com.xyz.abc D/FA: Debug-level message logging enabled 
05-08 21:18:34.182 4597-4597/com.xyz.abc D/FA: AppMeasurement singleton hash: 1038524578 
05-08 21:18:34.196 4597-4597/com.xyz.abc I/FA: To enable faster debug mode event logging run: 
                adb shell setprop debug.firebase.analytics.app com.xyz.abc 
05-08 21:18:34.235 4597-4597/com.xyz.abc I/FirebaseCrash: FirebaseCrash reporting initialized [email protected] 
05-08 21:18:34.235 4597-4597/com.xyz.abc I/FirebaseInitProvider: FirebaseApp initialization successful 
05-08 21:18:34.236 4597-4597/com.xyz.abc I/InstantRun: starting instant run server: is main process 
05-08 21:18:34.240 4597-4597/com.xyz.abc I/art: Rejecting re-init on previously-failed class java.lang.Class<com.xyz.abc.database.helper.AbcDatabaseHelper> 
05-08 21:18:34.240 4597-4597/com.xyz.abc I/art: Rejecting re-init on previously-failed class java.lang.Class<com.xyz.abc.database.helper.AbcDatabaseHelper> 
05-08 21:18:34.240 4597-4597/com.xyz.abc I/art: Rejecting re-init on previously-failed class java.lang.Class<com.xyz.abc.database.helper.AbcDatabaseHelper> 
05-08 21:18:34.240 4597-4597/com.xyz.abc I/art: Rejecting re-init on previously-failed class java.lang.Class<com.xyz.abc.database.helper.AbcDatabaseHelper> 
05-08 21:18:34.249 4597-4597/com.xyz.abc I/art: Rejecting re-init on previously-failed class java.lang.Class<com.xyz.abc.database.helper.AbcDatabaseHelper> 
05-08 21:18:34.249 4597-4597/com.xyz.abc D/AndroidRuntime: Shutting down VM 
05-08 21:18:34.250 4597-4597/com.xyz.abc E/UncaughtException: java.lang.NoClassDefFoundError: com.xyz.abc.database.helper.AbcDatabaseHelper 
                    at com.xyz.abc.database.daos.UserRecordDao.<init>(UserRecordDao.java:32) 
                    at com.xyz.abc.AbcApplication.onCreate(AbcApplication.java:140) 
                    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012) 
                    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553) 
                    at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 
                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                    at android.os.Looper.loop(Looper.java:135) 
                    at android.app.ActivityThread.main(ActivityThread.java:5254) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at java.lang.reflect.Method.invoke(Method.java:372) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
05-08 21:18:34.261 4597-4638/com.xyz.abc I/DynamiteModule: Considering local module com.google.android.gms.tagmanager:8 and remote module com.google.android.gms.tagmanager:9 
05-08 21:18:34.261 4597-4638/com.xyz.abc I/DynamiteModule: Selected remote version of com.google.android.gms.tagmanager, version >= 9 
05-08 21:18:34.285 4597-4638/com.xyz.abc W/GoogleTagManager: No container asset found in /assets/containers. Checking top level /assets directory for container assets. 
05-08 21:18:34.304 4597-4638/com.xyz.abc W/GoogleTagManager: Tag Manager's event handler WILL NOT be installed (no container loaded) 
05-08 21:18:34.305 4597-4638/com.xyz.abc I/GoogleTagManager: Tag Manager initilization took 37ms 
05-08 21:18:34.309 4597-4638/com.xyz.abc D/FA: Logging event (FE): _ae, Bundle[{_o=crash, timestamp=1494292714250, fatal=1}] 
05-08 21:18:34.471 4597-4597/com.xyz.abc E/AndroidRuntime: FATAL EXCEPTION: main 
                  Process: com.xyz.abc, PID: 4597 
                  java.lang.NoClassDefFoundError: com.xyz.abc.database.helper.AbcDatabaseHelper 
                   at com.xyz.abc.database.daos.UserRecordDao.<init>(UserRecordDao.java:32) 
                   at com.xyz.abc.AbcApplication.onCreate(AbcApplication.java:140) 
                   at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012) 
                   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553) 
                   at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 
                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                   at android.os.Looper.loop(Looper.java:135) 
                   at android.app.ActivityThread.main(ActivityThread.java:5254) 
                   at java.lang.reflect.Method.invoke(Native Method) 
                   at java.lang.reflect.Method.invoke(Method.java:372) 
                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
05-08 21:22:57.870 4597-4597/? I/Process: Sending signal. PID: 4597 SIG: 9 
+0

你的'minSdkVersion'是什麼? – azizbekian

+0

分機{ 的minSdkVersion = 16 targetSdkVersion = 22 compileSdkVersion = COMPILE_SDK_VERSION爲INT buildToolsVersion = 「25.0.2」 } – windchime

+0

是'AbcDatabaseHelper'你寫的還是從第三方庫的一類? –

回答

0

我找到了解決這個問題的方法。這應該是一個multidex問題。當我減少依賴的數量時,這個問題不再發生。

最後我改變

compile 'com.google.android.gms:play-services:10.0.1' 

compile 'com.google.android.gms:play-services-maps:10.0.1' 

,因爲我只需要地圖,並保持所有其他依賴。

仍然不確定爲什麼它的行爲如此清晰API 23和24以與API 22和以下不同的方式處理Multidex。

希望這可以幫助任何有類似問題的人。

1

首先,嘗試清理項目。過去面對類似的問題,清理和重建項目解決了我的問題。


Secnd,如果您的AbcDatabaseHelper類不公開,它將只能訪問相同的包/文件夾。

變化

class AbcDatabaseHelper { 

} 

public class AbcDatabaseHelper { 

} 

而且也,一些圖書館和方法可以缺少三星設備,如S4迷你,迷你S3,S4,注2等一些第三方庫可能無法在某些情況下工作。

0

使用異常類是捕捉所有異常

0

沒有爲ormilite另一個叉,在這個github回購與API 22工作。您只需添加到您的gradle產出:

buildscript { 
    repositories { 
    ... 
    mavenCentral() 
    } 

    dependencies { 
    ... 
    classpath 'com.github.stephanenicolas.ormgap:ormgap-plugin:1.0.0-SNAPSHOT' 
    } 
} 

apply plugin: 'android' 
apply plugin: 'ormgap' 

它有一個example,你應該檢查看個體差異。我希望它能幫助你!