【问题标题】:App crash if enabled proguard如果启用 proguard,应用程序崩溃
【发布时间】:2018-01-09 17:50:11
【问题描述】:

如果使用此代码在我的应用程序中启用 proguard:

release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

只有在 Play Store 中发布的应用程序才会崩溃,当尝试从 Android Studio 应用程序以调试或正常模式运行时不会崩溃。

崩溃时出错:

Error inflating class android.support.v7.widget.Toolbar

Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.v7.widget.Toolbar

 Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.v7.widget.Toolbar

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.aj.a()' on a null object reference

我正在使用最新版本的 support.v7:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4:27.0.2'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'      
}

今天之前一切正常=(

德克斯特说:

-dontwarn android.support.v7.**
-keep class android.support.v7.widget.** { *; }

它可以工作,但为什么在更新 android studio 后我总是有问题?为什么 Android Studio 在今天最新版 proguard 取消小部件之后?

【问题讨论】:

  • 谢谢你。这就是我开始讨厌 Google/Android 等的原因。你照本宣科。你做他们想做的一切。没有任何效果。为什么 proguard 会删除导入和引用、声明和使用的库?然后只有在测试来自 playstore 的签名 apk 时,当每个人都已经在手机上拥有它时,你才会发现。现在我必须在上传之前测试已签名、缩小的 apk

标签: java android-studio crash


【解决方案1】:

也许 proguard 删除了这个类,如果你想保留它,你可以禁用 proguard 以避免这个错误,你将不得不更改 proguard 设置

-dontwarn android.support.v7.**
-keep class android.support.v7.widget.** { *; }

【讨论】:

  • 谢谢,但是为什么Android Studio的任何更新我都有10000个问题?在今天更新 Android Studio 之前不要删除这个类...
【解决方案2】:

尝试在 Gradle 中添加:

android {  
    defaultConfig {  
        vectorDrawables.useSupportLibrary = true  
    }
}

并对所有项目执行完全清理和重建。

【讨论】:

    猜你喜欢
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 2014-03-09
    • 1970-01-01
    相关资源
    最近更新 更多