启用混淆器后收到警告和错误
Getting warnings and errors after enabling proguard
我为我的发布版本启用了混淆器,当我 运行 项目时,我得到 these warnings and errors。这是我的 buildTypes
块:
buildTypes {
release {
minifyEnabled true
//shrinkResources true
signingConfig signingConfigs.myConfig
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
构建消息太长 post 在这里,所以已经把外部 link。
这些警告的原因是什么?我做错了什么吗?我该如何解决这个问题?
警告中提到的每个库都有自己的 proguard 规则,您必须将这些规则放入您的 proguard-rules.pro。例如,您可以在 http://jakewharton.github.io/butterknife/ "Proguard" 部分找到 ButterKnife 的规则。
对于您正在使用的任何外部库,您需要在 proguard.pro 文件中添加规则。
例如在我的项目中,这些是我为改造和 okhttp 添加的混淆器规则
# 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 warnings and errors。这是我的 buildTypes
块:
buildTypes {
release {
minifyEnabled true
//shrinkResources true
signingConfig signingConfigs.myConfig
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
构建消息太长 post 在这里,所以已经把外部 link。 这些警告的原因是什么?我做错了什么吗?我该如何解决这个问题?
警告中提到的每个库都有自己的 proguard 规则,您必须将这些规则放入您的 proguard-rules.pro。例如,您可以在 http://jakewharton.github.io/butterknife/ "Proguard" 部分找到 ButterKnife 的规则。
对于您正在使用的任何外部库,您需要在 proguard.pro 文件中添加规则。
例如在我的项目中,这些是我为改造和 okhttp 添加的混淆器规则
# 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>;
}
这些规则取自
因此您需要为每个库类似地检查要添加的规则。