简体   繁体   中英

Android: NoClassDefFoundError only on release build

I'm on Android Studio and trying to build my project on release mode.
Everything is OK in debug mode however below errors occur in release mode...

08-26 17:59:05.599  31696-31931/? W/System.err﹕ java.lang.NoClassDefFoundError: a.a.b.l
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at java.lang.Class.classForName(Native Method)
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at java.lang.Class.forName(Class.java:308)
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at java.lang.Class.forName(Class.java:272)
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at com.a.a.a.a(Unknown Source)
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at com.a.a.a.a(Unknown Source)
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at com.a.a.e.b(Unknown Source)
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at com.a.a.e.a(Unknown Source)
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at com.a.e.a.uncaughtException(Unknown Source)
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
08-26 17:59:05.599  31696-31931/? W/System.err﹕ at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
08-26 17:59:05.600  31696-31931/? E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
    Process: com.soonoo.mobilecampus, PID: 31696
    java.lang.RuntimeException: An error occured while executing doInBackground()
            at android.os.AsyncTask$3.done(AsyncTask.java:300)
            at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
            at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
            at java.util.concurrent.FutureTask.run(FutureTask.java:242)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.ExceptionInInitializerError
            at a.a.b.l.a(Unknown Source)
            at a.a.b.m.<clinit>(Unknown Source)
            at a.a.b.f.<init>(Unknown Source)
            at a.a.b.e.<init>(Unknown Source)
            at a.a.c.di.b(Unknown Source)
            at a.a.c.di.a(Unknown Source)
            at a.a.c.b.a(Unknown Source)
            at a.a.c.ae.b(Unknown Source)
            at a.a.a.a(Unknown Source)
            at com.soonoo.mobilecampus.mainlist.h.a(Unknown Source)
            at com.soonoo.mobilecampus.mainlist.h.doInBackground(Unknown Source)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.NullPointerException: in == null
            at java.util.Properties.load(Properties.java:246)
            at a.a.b.l.d(Unknown Source)
            at a.a.b.l.<clinit>(Unknown Source)
            at a.a.b.l.a(Unknown Source)
            at a.a.b.m.<clinit>(Unknown Source)
            at a.a.b.f.<init>(Unknown Source)
            at a.a.b.e.<init>(Unknown Source)
            at a.a.c.di.b(Unknown Source)
            at a.a.c.di.a(Unknown Source)
            at a.a.c.b.a(Unknown Source)
            at a.a.c.ae.b(Unknown Source)
            at a.a.a.a(Unknown Source)
            at com.soonoo.mobilecampus.mainlist.h.a(Unknown Source)
            at com.soonoo.mobilecampus.mainlist.h.doInBackground(Unknown Source)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)

The problem is that exception messages do not display the name of classes, methods that occurs error.
All third party libraries I used in my project are specified in build.gradle .
How can I fix this?

The problem is basically the following:

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

If you set minifyEnabled to false, it should fix your problem. If you want to use the minify feature then you can add progaurd rules to your build.gradle. For instance for the Butterknife library you have to add the following:

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

Glad I could help

In my case it was working for all database tables, except one which was specifically passed as argument inside UI Navigation So, if you are using UI Navigation with serializable argument type as one of the roomdb table , make sure you are not mentioning the class name of it in the XML file (as that will be changed in release DEX/minification process.)

XML file: Navigation.xml containing

<navigation>
        <fragment> 
            <argument android:name="questionObj" app:argType="roomdb.db.question" /> // removed for Fixing
            <action
            android:id="@+id/action_q1_to_q2">
        </fragment> 
    </navigation>

<argument ..... /> line was removed as a fix.

bundle!!.getSerializable("questionObj") as Question?

Should be used for passing

Errors were helpful & accurate

W/System.err: Caused by: java.lang.RuntimeException: Exception inflating navigation/navigation line 83
W/System.err: Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: database.db.Question
W/System.err: Caused by: java.lang.ClassNotFoundException: database.db.Question
W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "database.db.Question" on path: DexPathList[[zip file "/data/app/appname-zu2-cBYoT7e345HeXbjQsgtpA==/base.apk"],nativeLibraryDirectories=[/data/app/appname-zu2-cBYoT7e345HeXbjQsgtpA==/lib/arm64, /system/lib64, /product/lib64]]
I/PackageManager.DexOptimizer: Running dexopt (dexoptNeeded=-3) on: /data/app/appname-zu2-cBYoT7e345HeXbjQsgtpA==/base.apk pkg=appname isa=arm64 dexoptFlags=boot_complete,profile_guided,enable_hidden_api_checks targetFilter=speed-prof

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM