Android Studio发布签名apk:app:transformClassesAndResourcesWithProguardForRelease java.io.IOException

时间:2016-05-26 10:05:48

标签: android android-studio apk release sign

我刚刚更新到Android Studio 2.1.1,我正在尝试构建一个发布签名的apk但失败并出现以下错误。我该如何解决这个问题?

':app:transformClassesAndResourcesWithProguardForRelease'.
    > java.io.IOException: Please correct the above warnings first.

这是build.gradle(module:app)

完整版:https://gist.github.com/anonymous/65bb2edf94ea58c50de8e0ff107555ce

...
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.company.project"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 13
        versionName "1.5"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        checkReleaseBuilds false
    }
}

更多关于错误消息转储 https://gist.github.com/anonymous/9d822c530011b48dab1da60267f9b471

更新:

proguard-rules.pro的内容 https://gist.github.com/anonymous/9d822c530011b48dab1da60267f9b471

/Users/xxxx/Library/Android/sdk/tools/proguard/proguard-android.txt的内容 https://gist.github.com/anonymous/d5cdfbfd7c1bfe74d594993feb35bd62

/Users/xxxx/Library/Android/sdk/tools/proguard/proguard-project.txt的内容 https://gist.github.com/anonymous/d04cd0299029d4fdd648fb782f2e3021

1 个答案:

答案 0 :(得分:0)

由于您尚未在proguard-android.txt文件中添加proguard规则,我建议您添加所有必要的规则,以便从您的项目中发布apk。

对于retrofit,您需要添加以下规则:

-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

您还需要添加其他规则,例如

-keepattributes *Annotation*
-keep class com.google.android.gms.internal.*

-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.BackupAgent
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.support.v4.app.DialogFragment

-keep class com.google.android.gms.maps.** { *; }
-keep interface com.google.android.gms.maps.** { *; }

-keepclassmembers class * implements android.os.Parcelable {
    static *** CREATOR;
}
# The Maps API uses serialization.
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

这对于大多数项目都很常见,而且我已经用于我的项目,请在使用之前检查整个规则。