【问题标题】:Android : Cannot creating signed APK after enabling ProguardAndroid:启用 Proguard 后无法创建签名的 APK
【发布时间】:2023-08-08 15:57:01
【问题描述】:

我只是在我的项目中启用 proguard 。之后,我使用 debug 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.**,但仍然遇到同样的问题

谁能帮我解决这个问题。

【问题讨论】:

  • 使用minifyEnabled false
  • @Binil S 你能发布你的警告吗?
  • @IntelliJAmiya 我想他想启用 proguard 所以minifyEnabled 应该是true
  • 是的,这就是为什么我将 minifyEnabled 设为 true @IntelliJAmiya
  • 警告更新,你能检查@Dinesh Kannan

标签: android build android-gradle-plugin build.gradle


【解决方案1】:

有关您的 google play services proguard 问题,请参阅此处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'

【讨论】:

  • 清除清单中的所有重复权限并尝试上述 lint 选项,但我仍然有同样的问题@Dinesh Kannan
【解决方案2】:

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

因此,要删除警告,请将其添加到您的 proguard-rules.pro 中。

-dontwarn com.google.android.**

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

【讨论】: