【发布时间】:2016-04-21 04:43:03
【问题描述】:
我正在 Android Studio 中开发 android 应用程序。当我在没有 Proguard 的情况下构建导出签名 APK 的项目时没有问题,但是当我尝试使用 ProGuard(minifyEnabled true) 构建项目时,Proguard 构建失败并出现如下错误:
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Can't write [user\myapplication\app\build\intermediates\transforms\proguard\release\jars\3\1f\main.jar] (Can't read [user]sdkpath\SDK\build-tools\23.0.0\renderscript\lib\renderscript-v8.jar(;;;;;;**/*.class)] (Duplicate zip entry [renderscript-v8.jar:android/support/annotation/Keep.class]))
这是我的 build.gradle 代码
...
defaultConfig {
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
dependencies {
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile project(':libraries:gpuimage')
compile 'it.sephiroth.android.library.horizontallistview:hlistview:1.2.2'
}
这是我的 proguard-rule.pro
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keep class *.R
-keep class *.R$* {*;}
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}
## Google AdMob specific rules ##
## https://developers.google.com/admob/android/quick-start ##
-keep public class com.google.ads.** {
public *;
}
## Google Analytics 3.0 specific rules ##
-keep class com.google.analytics.** { *; }
#-keep class it.sephiroth.** {*;}
-dontwarn it.sephiroth.**
Proguard 疑难解答这样说
警告:无法写入资源...重复的 zip 条目 您的输入 jar 包含多个具有相同名称的资源文件。 ProGuard 像往常一样继续复制资源文件,跳过任何以前使用过的名称的文件。再一次,警告可能表明存在一些问题,因此建议删除重复项。一种方便的方法是在输入 jar 上指定过滤器。没有关闭这些警告的选项。
android The standard Android build process automatically specifies the input jars for you. There may not be an easy way to filter them to remove these warnings. You could remove the duplicate resource files manually from the input and the libraries.
但我没有弄清楚我在构建中添加了两次哪个 jar..!
【问题讨论】:
标签: android-studio gradle android-proguard