Android:启用Proguard

时间:2016-02-10 08:24:18

标签: android build android-gradle build.gradle

我只在项目中启用 proguard 。之后,我使用调试apk 成功运行apk。

当我尝试创建已签名的Apk 时收到错误

Error:Execution failed for task ':app:proguardRelease'.
 > java.io.IOException: Please correct the above warnings first.

我的Gradle文件

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.android4dev.navigationview"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.github.traex.rippleeffect:library:1.3'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.google.android.gms:play-services:8.1.0'

}

警告

Warning:com.google.android.gms.internal.zzhu: can't find referenced class android.security.NetworkSecurityPolicy
Warning:there were 3 unresolved references to classes or interfaces.
     You may need to add missing library jars or update their versions.
     If your code works fine without the missing classes, you can suppress
     the warnings with '-dontwarn' options.
     (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
 :app:proguardRelease FAILED
  Error:Execution failed for task ':app:proguardRelease'.
  > java.io.IOException: Please correct the above warnings first.

我尝试-dontwarn org.apache.lang.**,但仍然遇到同样的问题

请帮助我解决这个问题。

2 个答案:

答案 0 :(得分:0)

对于您的Google Play服务程序问题,请参阅此处com.google.android.gms.internal.zzhu: can't find referenced class android.security.NetworkSecurityPolicy

还尝试解决清单重复问题,或者可以在发布版本中禁用lint。 禁用发布版本中的lint检查将此添加到build.gradle文件

lintOptions {
        checkReleaseBuilds false
    } 

尝试更新build.gradle中的播放服务版本

compile 'com.google.android.gms:play-services-analytics:8.3.0'

答案 1 :(得分:0)

根据您发布的警告日志,警告似乎来自 com.google.android.gms.internal.zzhu 包,而不是来自 org.apache。郎即可。

所以要删除警告,请在proguard-rules.pro。

中添加
-dontwarn com.google.android.**

告诉我们当时发生了什么!