Android K上的BuildConfig NoClassDefFoundError

时间:2016-10-03 23:07:57

标签: android android-studio gradle

我最近将我的构建环境升级到Android studio 2.2,JDK 1.8(带插孔),我正在使用带有gradle-2.14.1的gradle包装器。我的构建/发布变体在任何Android版本>上正确编译和运行K.但是,当我尝试在Android K设备上运行代码时,代码编译正常并且apk正确生成但代码立即崩溃,下面有堆栈跟踪,因为代码似乎无法找到BuildConfig类。非常感谢我可以研究的任何指针。谢谢!

  

致命的例外:主要                                                                            过程:com.trail.android.debug,PID:21045                                                                            java.lang.NoClassDefFoundError:com.trail.android.BuildConfig                                                                                在   com.trail.android.TrailApplication.attachBaseContext(TrailApplication.java:41)                                                                                在android.app.Application.attach(Application.java:181)                                                                                在   android.app.Instrumentation.newApplication(Instrumentation.java:991)                                                                                在   android.app.Instrumentation.newApplication(Instrumentation.java:975)                                                                                在android.app.LoadedApk.makeApplication(LoadedApk.java:511)                                                                                在   android.app.ActivityThread.handleBindApplication(ActivityThread.java:4317)                                                                                在android.app.ActivityThread.access $ 1500(ActivityThread.java:135)                                                                                在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1256)                                                                                在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                在android.os.Looper.loop(Looper.java:136)                                                                                在android.app.ActivityThread.main(ActivityThread.java:5017)                                                                                at java.lang.reflect.Method.invokeNative(Native Method)                                                                                在java.lang.reflect.Method.invoke(Method.java:515)                                                                                在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)                                                                                在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)                                                                                在dalvik.system.NativeStart.main(本地方法)

1 个答案:

答案 0 :(得分:0)

这与https://code.google.com/p/android/issues/detail?id=224026

有关

一些类进入二级dex文件(在我的情况下,BuildConfig.class是在二级dex中),并且KitKat无法在二级dex中找到(这在Android L及以上和在L之前自动工作的多索支持图书馆应该已经处理好这个但是我猜错了。要解决此问题,请在jackOptions中添加以下内容。

 jackOptions {
            enabled true
            additionalParameters("jack.dex.output.policy" : "multidex")
            additionalParameters("jack.preprocessor" : "true")
            additionalParameters("jack.preprocessor.file" : "legacyMultidexInstallation.jpp")
            additionalParameters("jack.dex.output.multidex.legacy": "true")
        }

通过此修复,它对我有用。