I get the same error as java.lang.ClassNotFoundException: Didn't find class, but only in version 4.4
I tried various ways but couldn't solve it
Is there a way to solve this problem?
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sinwho.timer/com.sinwho.timer.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.sinwho.timer.MainActivity" on path: DexPathList[[zip file "/data/app/com.sinwho.timer-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.sinwho.timer-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2131)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)
at android.app.ActivityThread.access800ドル(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sinwho.timer.MainActivity" on path: DexPathList[[zip file "/data/app/com.sinwho.timer-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.sinwho.timer-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2122)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)
at android.app.ActivityThread.access800ドル(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
-
Version 4.4 of what? Of Android? That's almost 6 years old.Joseph Sible-Reinstate Monica– Joseph Sible-Reinstate Monica2019年09月06日 03:28:02 +00:00Commented Sep 6, 2019 at 3:28
-
Did you enable multidexing?Mr. Patel– Mr. Patel2019年09月06日 03:35:24 +00:00Commented Sep 6, 2019 at 3:35
-
Yes it is Android version 4.4leegill– leegill2019年09月06日 03:38:05 +00:00Commented Sep 6, 2019 at 3:38
-
i added multiDexEnabled trueleegill– leegill2019年09月06日 03:38:46 +00:00Commented Sep 6, 2019 at 3:38
-
possible duplicate stackoverflow.com/q/22399572/4854891Jakir Hossain– Jakir Hossain2019年09月06日 03:44:24 +00:00Commented Sep 6, 2019 at 3:44
1 Answer 1
In android 4.4, we are facing the issue about: Declare classes required in the primary DEX file. mentioned in here: (https://developer.android.com/studio/build/multidex#keep)
From Gradle 2.2.0 (Released in September 2016) you can use multiDexKeepFile api
android {
buildTypes {
debug {
...
multiDexEnabled true
multiDexKeepFile file('multidex_keep_file.txt')
}
}
}
Where multidex_keep_file.txt is file with single class per line which needs to be explicitly added to the main dex
com/test/TestClass.class
com/test/TestClass.class
Another approach is: use multiDexKeepProguard to keep whole package
-keep class com.test.** { *; }