3

I'm having an app and which works in android Lollipop and above, if I installed the app in android Kitkat device, the application crashes and show the error as below:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.SplashActivity}: java.lang.ClassNotFoundException: Didn't find class "com.SplashActivity" on path: DexPathList[[zip file "/data/app/com.partner-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.partner-1, /system/lib]] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2131) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5146) 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:732) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.SplashActivity" on path: DexPathList[[zip file "/data/app/com.partner-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.partner-1, /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:2271)  at android.app.ActivityThread.access$800(ActivityThread.java:144)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:136)  at android.app.ActivityThread.main(ActivityThread.java:5146)  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:732)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)  at dalvik.system.NativeStart.main(Native Method) 

I tried a lot and was not able to fix it, most of the answers are for eclipse projects.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Sachin Varma
  • 2,175
  • 4
  • 28
  • 39

3 Answers3

1

The reason for api 21 on is:

Android 5.0 (API level 21) and higher uses a runtime called ART which natively supports loading multiple DEX files from APK files. ART performs pre-compilation at app install time which scans for classesN.dex files and compiles them into a single .oat file for execution by the Android device. Therefore, if your minSdkVersion is 21 or higher, you do not need the multidex support library.

From this guide: https://developer.android.com/studio/build/multidex.html

I solved the class not found error by naming my classes like this:

[Activity(Name = "somepackage.custombuttonrenderer")]
public class CustomButtonRenderer: ButtonRenderer
{ }

Here is my answer: Why is my custom ButtonRenderer not working?

IvanF.
  • 513
  • 10
  • 18
1

Update you app level build.gradle file:

implementation 'com.android.support:multidex:1.0.0'

And update you application class with :

@Override
public void onCreate() {
    super.onCreate();
    MultiDex.install(this);
}
0

This worked to me: Add this in your APLICATION class.

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(getBaseContext());
}

Explanation: Android app (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536

Versions of the platform prior to Android 5.0 (API level 21) use the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. In order to get around this limitation, you can add the multidex support

Bilal
  • 1
  • 4