android - API < 21 的 java.lang.VerifyError

标签 android gradle android-multidex

我正在使用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/

相关文章:

java - 类加载器 : Resources from Callee

intellij-idea - 具有多个 gradle 子项目的 IntelliJ IDEA

android - 错误 :Execution failed for task ':app:transformClassesWithDexForDebug' - for multidex app

android - PreferenceActivity 中的自定义标题栏(摘要)

Android:当 "focus"在特定 View 上时,如何在对讲(可访问性)期间中断?

java - 将 YouTube 数据 API 添加到 Android Studio

android - versionCode 总是被覆盖为 -1

java - 添加第三方.aar文件后无法合并dex

android - 使用 multidex=true 构建时 AndroidManifest 中的应用程序名称

java - Android 以编程方式创建列表