我尝试生成已签名的APK失败。
我的proguard-rules.pro
文件:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
# ================ Google Play Services ================
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
# ======================================================
# ============ Corrige erros de compilação =============
-dontwarn android.support.**
-keeppackagenames org.jsoup.nodes
-dontwarn okio.**
# ======================================================
# ==== crashlytics ====
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
# =====================
我的依赖项:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services-ads:9.2.0'
compile 'com.google.android.gms:play-services-analytics:9.2.0'
compile 'com.android.support:design:23.4.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}
compile 'org.jsoup:jsoup:1.9.2'
compile 'com.github.hotchemi:android-rate:1.0.1'
compile 'com.github.curioustechizen.android-ago:library:1.3.2'
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
compile 'com.amitshekhar.android:android-networking:0.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
}
构建错误:
Error:Execution failed for task ':mobile:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
:mobile:transformClassesAndResourcesWithProguardForRelease FAILED
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
答案 0 :(得分:1)
如果你想要做的就是创建一个签名的APK,只需添加
即可-ignorewarnings
标记到您的proguard-rules.pro
文件。这将忽略Proguard发出的所有警告,并简单地生成签名的APK。
但是,以这种方式忽略所有警告可能会产生一些意想不到的后果(关键类被剥离,功能受损等)。我强烈建议您检查每个发出的警告,并分别处理每个警告。要么以规定的方式正确处理每个警告,要么使用
-dontwarn
如果警告是虚假的,则为特定类或库标记。
迭代这个过程,直到所有这些副作用都被消除,你将获得一个Proguard优化的APK,没有任何问题。