I am using productFlavours in my application. I also use multi dex.
defaultConfig { multiDexEnabled true minSdkVersion 17 targetSdkVersion 22 ... } productFlavors { prodFlavor1{...} prodFlavor2{...} } dependencies { compile 'com.android.support:multidex:1.0.1' ... }
In the Application class:
@Override public void onCreate() { MultiDex.install(getApplicationContext()); super.onCreate(); }
I have added the code above for Android versions below 5.
Then the next structure with two slightly different versions of MainActivity (MainActivity extends AppCompatActivity) starts at a certain point in the application, clicks the button.
app/src/prodFlavor1/.../MainActivity app/src/prodFlavor2/.../MainActivity
In prodFlavor1 , MainActivity begins immediately after SplashActivity . In prodFlavor2 , MainActivity .
This worked a long time before and even after I added this part using multidex , but suddenly bent over, working without explanation. Even if I delete the code that references multidex, I get the same thing.
When I switch to prodVersion2 , everything works. But when I switch to prodVersion1 , I get:
startActivity(new Intent(TutorialActivity.this,MainActivity.class));
Nexus 5 with Android 6:
Process: com.mpackage, PID: 30807 java.lang.LinkageError: com.mpackage.activities.MainActivity at dalvik.system.DexFile.defineClassNative(Native Method) at dalvik.system.DexFile.defineClass(DexFile.java:226) at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219) at dalvik.system.DexPathList.findClass(DexPathList.java:338) at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at com.gossip.activities.TutorialActivity$1.handleMessage(TutorialActivity.java:52) 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)
In the Nexus4 emulator with Android 4.4:
java.lang.NoClassDefFoundError: com.mpackage.activities.MainActivity at com.gossip.activities.TutorialActivity$1.handleMessage(TutorialActivity.java:52) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) 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:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)
UPDATE:
It seems that the error was caused by the fact that I added the isResumed() method to MainActivity , so the (Native Method) error is different from 6.0 from 4.4.