我正在使用MultiDex
在我的应用程序中支持超过 65k 的方法。在 api 21 上它运行良好,因为它进行了 predex 构建。在 api 21 下,我的 Application
崩溃了使用此堆栈跟踪:
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)
这是我的gradle
具有不同风格的文件(简化),用于在调试中使用 predex 进行编译:
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'
}
这是我的 Application
:
public class MyApplication extends CustomLibraryApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
在我的 list 中 <application>
我有android:name=".MyApplication"
诸如“排除某些 Google Play 服务”或“扩展 MultiDexApplication”之类的解决方案在这种情况下没有用。
最佳答案
已解决
问题是...鼓声...buildToolsVersion
!
我将 gradle 中的 buildToolsVersion
(仅 buildToolsVersion
)从 22.0.1
更改为 23 rc3
(预览 channel 中的最后一个)并且它与具有 multidex 的 api < 21 配合良好。
关于android - API < 21 的 java.lang.VerifyError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31587765/