2016-07-04 230 views
-3

我無法嘗試生成簽名的APK。Android - 使用Proguard創建簽名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:[email protected]') { 
     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. 

回答

1

如果你想要做的是創建一個簽名APK,只需添加

-ignorewarnings 

標記爲您的proguard-rules.pro文件。這將忽略Proguard發出的所有警告,並簡單地生成已簽名的APK。

但是,以這種方式忽略所有警告可能會產生一些意想不到的後果(嚴重級別被剝離,功能受損等)。我強烈建議您檢查每個發出的警告,並分別處理每個警告。要麼按照規定的方式正確處理每個警告,要麼使用

-dontwarn 

如果警告是虛假的,則爲特定類或庫使用標記。

迭代該過程直到消除所有這些副作用,並且您將擁有一個Proguard優化的APK,而不會出現任何問題。

+0

不知怎的,你幫我覺得 – Josinaldo

+0

好吧,在我的情況下,我決定把「-dontwarn com.squareup.okhttp。**」(LIB畢加索)文件中的「proguard-rules.pro」 – Josinaldo

+0

你能夠建立一個沒有任何副作用的簽名APK? –

相關問題