2

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.access$800(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.access$800(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) 
6
  • Version 4.4 of what? Of Android? That's almost 6 years old. Commented Sep 6, 2019 at 3:28
  • Did you enable multidexing? Commented Sep 6, 2019 at 3:35
  • Yes it is Android version 4.4 Commented Sep 6, 2019 at 3:38
  • i added multiDexEnabled true Commented Sep 6, 2019 at 3:38
  • possible duplicate stackoverflow.com/q/22399572/4854891 Commented Sep 6, 2019 at 3:44

1 Answer 1

4

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.** { *; }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.