Samsung S4 API 21上的android ormlite NoClassDefFoundError

时间:2017-05-04 16:10:05

标签: android ormlite

Android项目在Samsung S7 API 24,Nexus 6 API 24,API 23 Emulator,Pixel API 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.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: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.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

4 个答案:

答案 0 :(得分:1)

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

Secnd,如果您的AbcDatabaseHelper类不公开,则只能访问相同的包/文件夹。

变化

class AbcDatabaseHelper {

}

public class AbcDatabaseHelper {

}

此外,三星设备上可能缺少一些库和方法,如S4 Mini,S3 Mini,S4,Note 2等。某些第三方库在某些情况下可能无效。

答案 1 :(得分:1)

我找到了解决这个问题的方法。它应该是一个多指标问题。当我减少依赖项的数量时,这个问题不再发生。

最后我改变了

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。

希望这有助于任何有类似问题的人。

答案 2 :(得分:0)

使用异常类来捕获所有异常

答案 3 :(得分:0)

在这个github回购中,有另一个ormilite的分支与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你应该检查以查看不同之处。我希望它可以帮到你!