因此,我在我的项目中通过将android.enableR8=true添加到gradle.properties来启用R8。这是我的gradle文件:
buildTypes {
release {
useProguard false
minifyEnabled true
debuggable false
multiDexEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
...但是当我运行一个构建时,当应用程序启动时,我得到了这个崩溃:
java.lang.RuntimeException: Unable to instantiate application com.example.application.MyApplication: java.lang.NullPointerException: throw with null exception
at android.app.LoadedApk.makeApplication(LoadedApk.java:1069)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: throw with null exception
at com.example.application.MyApplication.<init>(MyApplication.kt:18)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:50)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1120)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1061)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 我在我的proguard文件中添加了这些,这样R8就不会删除或混淆任何东西
-dontobfuscate
-dontshrink
-dontoptimize而应用程序仍然会崩溃。
我尝试通过在Gradle文件中将android.enableR8=false设置为gradle.properties和useProguard true来迁移到Proguard,应用程序运行良好,没有崩溃。
有人遇到过同样的问题吗?
顺便说一句,我的项目在Kotlin。
发布于 2020-09-15 20:16:15
问题是我们在一些模块中捆绑了android.jar,但它应该只在bootclasspath上,正如安卓团队在我在IssueTracker上创建的issue中所说的那样。
发布于 2020-09-04 22:26:37
我建议您查看R8的输出,看看是否有任何警告可以为您指明正确的方向。如果您可以一致地重现该问题,则可以向R8:https://issuetracker.google.com/issues/new?component=326788&template=1025938提交问题。
https://stackoverflow.com/questions/63741654
复制相似问题