I'm getting the following exception after running my app with minifyEnabled true
. But if I comment it out, the app opens just fine.
Error
AndroidRuntime E FATAL EXCEPTION: main
Process: my.app.android, PID: 24808
java.lang.NoClassDefFoundError: Failed resolution of: [Ljava/nio/file/LinkOption;
at af.h.<clinit>(JavaFlexibleTypeDeserializer.kt:18)
at pl.h.onCreate(MyApp.java:302)
at my.app.android.MyBaseApp.onCreate(MyBaseApp.kt:1)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.nio.file.LinkOption" on path: DexPathList[[zip file "/data/app/my.app.android-2/base.apk"],nativeLibraryDirectories=[/data/app/my.app.android-2/lib/x86, /data/app/my.app.android-2/base.apk!/lib/x86, /vendor/lib, /system/lib]]
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 af.h.<clinit>(JavaFlexibleTypeDeserializer.kt:18)
at pl.h.onCreate(MyApp.java:302)
at my.app.android.MyBaseApp.onCreate(MyBaseApp.kt:1)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.ClassNotFoundException: java.nio.file.LinkOption
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)
... 14 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Investigations
Keeping Classes in Proguard
I have already tried these lines in my proguard file, but was not able to fix the issue.
-keep class java.nio.file.** { *; }
-keep class java.nio.file.LinkOption { *; }
-keepclassmembers class java.nio.file.* {
<fields>;
<init>();
<methods>;
}
Updating Firebase Versions
I have tried updating Firebase to the latest version since earlier stacktrace shows a line from FirebaseInitProvider
but the error Failed resolution of: [Ljava/nio/file/LinkOption;
still show. It was changed into the stacktrace above after I updated the classpath "com.google.gms:google-services:4.3.14"
Desugaring
I have tried Desugaring with Java 11 nio
based from: https://developer.android.com/studio/write/java11-default-support-table using coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.0.1'
but ran into a different issue where FakeDependency.jar is empty. Here's the stack overflow link to this issue: Android Desugaring with nio Failed to transform FakeDependency.jar to match attributes
But Desugaring with coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.1'
build the project just fine, but still has LinkOption
stacktrace seen above.
Environments
This issue only exist when I build the app and install on an Android device at API Level 23 with minifyEnabled true
. But running it on an API Level 33 is just fine.
Below is a table of the different API Level with minifyEnabled
setting and their status after running the installed app.
| API Lvl | minifyEnabled | Status |
| ------- | ------------- | --------- |
| 23 | true | Crashed |
| 23 | false | Succeeded |
| 24 | true | Crashed |
| 24 | false | Succeeded |
| 33 | true | Succeeded |
| 33 | false | Succeeded |
I will be testing with API Levels 25, 26, and 27, and update the table above.
Any thoughts on what I might have missed or failed to do?