java.lang.NoClassDefFoundError:解析失败:联想K4上的App类注意运行android 6,API 23

时间:2018-05-08 13:02:57

标签: android guava noclassdeffounderror runtimeexception android-multidex

GroupingHelper是在应用程序本身的帮助程序包中定义的类,不是来自第三方库。仍然,在运行时找不到GroupingHelper并且我遇到了以下崩溃:

    --------- beginning of crash
05-08 18:18:33.181 24111-24111/com.pkg.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.pkg.app, PID: 24111
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/pkg/app/helpers/GroupingHelper$$Lambda$0;
        at com.pkg.app.helpers.GroupingHelper.<init>(GroupingHelper.java:21)
        at com.pkg.app.activities.TransactionActivity.<init>(TransactionActivity.java:35)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1072)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2473)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2667)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494)
        at android.os.Handler.dispatchMessage(Handler.java:111)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5776)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.pkg.app.helpers.GroupingHelper$$Lambda$0" on path: DexPathList[[zip file "/data/app/com.pkg.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.pkg.app-1/lib/arm64, /data/app/com.pkg.app-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at com.pkg.app.helpers.GroupingHelper.<init>(GroupingHelper.java:21) 
        at com.pkg.app.activities.TransactionActivity.<init>(TransactionActivity.java:35) 
        at java.lang.Class.newInstance(Native Method) 
        at android.app.Instrumentation.newActivity(Instrumentation.java:1072) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2473) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2667) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494) 
        at android.os.Handler.dispatchMessage(Handler.java:111) 
        at android.os.Looper.loop(Looper.java:207) 
        at android.app.ActivityThread.main(ActivityThread.java:5776) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
        Suppressed: java.lang.NoClassDefFoundError: com.pkg.app.helpers.GroupingHelper$$Lambda$0
        at dalvik.system.DexFile.defineClassNative(Native Method)
        at dalvik.system.DexFile.defineClass(DexFile.java:226)
        at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
        at dalvik.system.DexPathList.findClass(DexPathList.java:338)
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
                ... 16 more
        Suppressed: java.lang.ClassNotFoundException: com.pkg.app.helpers.GroupingHelper$$Lambda$0
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                ... 15 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

仅在Lenovo K4 Note上观察到崩溃到目前为止运行Android 6.0(API级别23)并且在其他测试的Android设备上运行正常。我有multidexEnabled为真。以下是我应用的build.gradle的片段:

compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
    applicationId "com.pkg.app"
    minSdkVersion 21
    targetSdkVersion 27
    multiDexEnabled true

    versionCode 7
    versionName "1.6"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
compileOptions {
    incremental true
    targetCompatibility 1.8
    sourceCompatibility 1.8
}

dexOptions {
    javaMaxHeapSize '4g'
}

1 个答案:

答案 0 :(得分:3)

问题是找不到com.pkg.app.helpers.GroupingHelper $$ Lambda $ 0而不是GroupingHelper类本身。我错误地解释了崩溃。

问题在于Google的Guava库版本。我开始相信'com.google.guava:guava:22.0-android'是Android&lt; = API level 23的正确库。对于API级别24+,'com.google.guava:guava:22.0'工作正常

所以,建议我们使用'com.google.guava:guava:22.0-android'虽然gradle继续说'com.google.guava:guava:22.0'是较新的版本。