android 三星 S4 上的 ormlite NoClassDefFoundError API 21

android ormlite NoClassDefFoundError on Samsung S4 API 21

android 项目 运行 在 Samsung S7 API 24、Nexus 6 API 24、API 23 Emulator、Pixel [=] 上没有问题27=] 23 和 Galaxy Note 23 API 模拟器。

当我在 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.access00(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:1.6.0@aar'
compile 'com.ogaclejapan.smarttablayout:utils-v4:1.6.0@aar'
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 com.google.android.gms.internal.zzbks@3824b269
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.access00(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.access00(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

首先,尝试清理项目。过去遇到过类似的问题,清理和重建项目解决了我的问题。


其次,如果您的 AbcDatabaseHelper class 不是 public,则只有 package/folder.

可以访问它

改变

class AbcDatabaseHelper {

}

public class AbcDatabaseHelper {

}

此外,三星设备(如 S4 Mini、S3 Mini、S4、Note 2 等)上可能缺少某些库和方法。某些第 3 方库在某些情况下可能无法正常工作。

使用异常Class 它捕获所有异常

在这个 github 存储库中,还有另一个适用于 api 22. 的 ormilite 分支。您只需将其添加到您的 gradle:

buildscript {
  repositories {
    ...
    mavenCentral()
  }

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

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

它有一个 example 您应该检查以查看差异。希望对你有帮助!

我找到了解决这个问题的方法。应该是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。

希望这对遇到类似问题的人有所帮助。