带有API的java.lang.VerifyError< 21

时间:2015-07-23 12:43:47

标签: android gradle multidex

我在我的应用中使用MultiDex来支持超过65,000种方法。在api 21上它运行良好,因为它执行prex构建。在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文件(简化),具有不同的风格,可以在debug中使用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);
    }
}

在我<application> android:name=".MyApplication"下的清单中,Application.OrganizerCopy [path to source template], ActiveDocument.FullName, [style name 1], wdOrganizerObjectStyles Application.OrganizerCopy [path to source template], ActiveDocument.FullName, [style name 2], wdOrganizerObjectStyles

解决方案如:&#34;排除部分Google Play服务&#34;或者&#34;扩展MultiDexApplication&#34;在这种情况下没用。

2 个答案:

答案 0 :(得分:3)

<强>解决

问题是......鼓声...... buildToolsVersion

我将我的gradle中的buildToolsVersion(仅buildToolsVersion)从22.0.1更改为23 rc3(预览频道中的最后一个),并且它与api&lt ; 21用multidex。

答案 1 :(得分:1)

另一个问题可能是当您使用某些库异常(对我来说是KeyPermanentlyInvalidated Exception)并且仅在api <21时出现。一旦将其更改为简单的Exception,一切都很好。这完美地帮助了我https://stackoverflow.com/a/16060251/12258664