在这种情况下使用 Proguard 时签名有什么问题?
What's wrong with signing while using Proguard on this case?
背景
最近我制作了一个新应用,当我尝试生成签名 APK 时,我发现了一个奇怪的行为:
- 项目文件夹中的任何位置都没有映射文件。
- 在 gradle 文件("minifyEnabled" 和 "shrinkResources")中启用最小化标志时,显示错误:
Error:Execution failed for task
':app:transformClassesAndResourcesWithProguardForRelease'.
Job failed, see logs for details
问题
事实是,我没有向项目添加任何可能导致 Proguard 规则不起作用的特殊内容。一切都以它们设置的默认方式使用。
这是应用 gradle 文件(用“...”替换了一些):
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias '...'
keyPassword '...'
storeFile file(...)
storePassword '...'
}
}
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId '...'
minSdkVersion 14
targetSdkVersion 25
versionCode 21
versionName "1.21"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// vectorDrawables.useSupportLibrary = true
}
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/LICENSE-FIREBASE_jvm.txt'
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:design:25.1.1'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-plus:10.2.0'
compile 'com.google.firebase:firebase-ads:10.2.0'
...
}
apply plugin: 'com.google.gms.google-services'
如你所见,和原来的差不多。
这是项目 gradle 文件:
// 顶级构建文件,您可以在其中添加所有通用的配置选项 sub-projects/modules。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-rc1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven {
url 'https://dl.bintray.com/baole/maven'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这里也没什么特别的。
我试过的
我也尝试将该项目与我的另一个项目进行比较,该项目与 Proguard 没有任何问题,但我找不到它们之间的任何特殊区别。
问题
为什么当我签署应用程序时 Proguard 没有开始处理项目?我应该怎么做才能使特殊标志也起作用?
可能你们中的某些人在 app.gradle 中的依赖项导致了由于无法导入或引用 类。您可以看到导入或引用错误 before/after "Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'." 行。这个问题的解决方案不是通过像这样修改 proguard-rule 来减少这种依赖关系......
-keep class com.itextpdf.** { *; }
-dontwarn com.itextpdf.**
是类似的问题。
我在 proguard 文件中找到了导致它的原因:
-keep class com.google.android.gms.** { ; }
解决方案是:
-keep class com.google.android.gms.** { *; }
背景
最近我制作了一个新应用,当我尝试生成签名 APK 时,我发现了一个奇怪的行为:
- 项目文件夹中的任何位置都没有映射文件。
- 在 gradle 文件("minifyEnabled" 和 "shrinkResources")中启用最小化标志时,显示错误:
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
Job failed, see logs for details
问题
事实是,我没有向项目添加任何可能导致 Proguard 规则不起作用的特殊内容。一切都以它们设置的默认方式使用。
这是应用 gradle 文件(用“...”替换了一些):
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias '...'
keyPassword '...'
storeFile file(...)
storePassword '...'
}
}
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId '...'
minSdkVersion 14
targetSdkVersion 25
versionCode 21
versionName "1.21"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// vectorDrawables.useSupportLibrary = true
}
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/LICENSE-FIREBASE_jvm.txt'
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:design:25.1.1'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-plus:10.2.0'
compile 'com.google.firebase:firebase-ads:10.2.0'
...
}
apply plugin: 'com.google.gms.google-services'
如你所见,和原来的差不多。
这是项目 gradle 文件:
// 顶级构建文件,您可以在其中添加所有通用的配置选项 sub-projects/modules。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-rc1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven {
url 'https://dl.bintray.com/baole/maven'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这里也没什么特别的。
我试过的
我也尝试将该项目与我的另一个项目进行比较,该项目与 Proguard 没有任何问题,但我找不到它们之间的任何特殊区别。
问题
为什么当我签署应用程序时 Proguard 没有开始处理项目?我应该怎么做才能使特殊标志也起作用?
可能你们中的某些人在 app.gradle 中的依赖项导致了由于无法导入或引用 类。您可以看到导入或引用错误 before/after "Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'." 行。这个问题的解决方案不是通过像这样修改 proguard-rule 来减少这种依赖关系......
-keep class com.itextpdf.** { *; }
-dontwarn com.itextpdf.**
我在 proguard 文件中找到了导致它的原因:
-keep class com.google.android.gms.** { ; }
解决方案是:
-keep class com.google.android.gms.** { *; }