Java.lang.VerifyError with API <21

I use MultiDex in my application to support more than 65 thousand methods. It works well on api 21 because it builds a predex. In api 21, I have a crash in my Application using this stacktrace:

 java.lang.VerifyError: mypackage/com/myapp/MyAppApplication at java.lang.Class.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1215) at android.app.Instrumentation.newApplication(Instrumentation.java:990) at android.app.Instrumentation.newApplication(Instrumentation.java:975) at android.app.LoadedApk.makeApplication(LoadedApk.java:502) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4537) at android.app.ActivityThread.access$1500(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5322) 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:829) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) at dalvik.system.NativeStart.main(Native Method) 

This is my gradle file (simplified) with various options for compiling with predex when debugging:

 apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "mypackage.com.myapp" targetSdkVersion 22 versionCode Integer.parseInt(new Date().format("yyMMddHH")) versionName "1.0" multiDexEnabled = true } productFlavors { normal { minSdkVersion 21 } beta { minSdkVersion 16 versionName "1.0.0_beta" } prod { minSdkVersion 16 } } dexOptions { javaMaxHeapSize "4g" } buildTypes { debug { minifyEnabled false debuggable true } release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:multidex:1.0.0' } 

And this is my Application :

 public class MyApplication extends CustomLibraryApplication { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } 

And in my manifest under <application> I have android:name=".MyApplication"

Solutions such as “exclude some Google Play services” or “extend MultiDexApplication” are not useful in this case.

+1
source share
1 answer

solvable

The problem was ... drumroll ... buildToolsVersion !

I changed buildToolsVersion in my gradle (only buildToolsVersion ) from 22.0.1 to 23 rc3 (the last from the preview channel) and it worked well with api <21 with multi-decks.

+2
source

All Articles