简体   繁体   English

启用Proguard后收到警告和错误

[英]Getting warnings and errors after enabling proguard

I enabled proguard for my release build and when I ran the project, I get these warnings and errors . 我为发布版本启用了proguard,并且在运行项目时收到这些警告和错误 Here is my buildTypes block: 这是我的buildTypes块:

buildTypes {
        release {
            minifyEnabled true
            //shrinkResources true
            signingConfig signingConfigs.myConfig
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

The build message was too long to post here so have put external link. 构建消息太长,无法在此处发布,因此已放置外部链接。 What is the reason for these warnings? 这些警告的原因是什么? Is there something I have done wrong? 我做错了什么吗? How can I fix this? 我怎样才能解决这个问题?

Each library mentioned in the warnings has its' own proguard rules which you have to put in your proguard-rules.pro. 警告中提到的每个库都有其自己的proguard规则,您必须将它们放在proguard-rules.pro中。 For example you can find ButterKnife's rules at http://jakewharton.github.io/butterknife/ "Proguard" section. 例如,您可以在http://jakewharton.github.io/butterknife/ “ Proguard”部分中找到ButterKnife的规则。

for any external library that you are using you need to add rules in your proguard.pro file. 对于您正在使用的任何外部库,您需要在proguard.pro文件中添加规则。

For example in my project these are the proguard rules I added for retrofit and okhttp 例如,在我的项目中,这些是我为改造和okhttp添加的proguard规则

# Retrofit 1.X

-keep class com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keep interface com.squareup.okhttp.** { *; }

-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit.**
-dontwarn rx.**

-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

These rules are taken from 这些规则取自

https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-square-retrofit.pro https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-square-retrofit.pro

So you need to check similarly for each library what are the rules to be added. 因此,您需要类似地检查每个库要添加的规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM