2017-03-05 109 views
0

我試圖生成minifyEnabled簽署過的APK在搖籃設置爲true:的Android minifyEnabled給出錯誤改裝

buildTypes { 
     release { 
      minifyEnabled true 
      shrinkResources true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

,並添加這些我ProGuard的文件:

-dontwarn okio.** 
-dontwarn retrofit.** 

,但我得到這些錯誤:

Information:Gradle tasks [:app:assembleRelease] 
Warning:retrofit2.Platform$Java8: can't find referenced method 'boolean isDefault()' in library class java.lang.reflect.Method 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup 
Warning:retrofit2.Platform$Java8: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 
Warning:there were 8 unresolved references to classes or interfaces. 
Warning:there were 1 unresolved references to library class members. 
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first. 
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'. 
> java.io.IOException: Please correct the above warnings first. 
Information:BUILD FAILED 

並且無法構建apk文件。我們不能將minifyEnabled設置爲true並使用翻新庫?這怎麼解決?

+0

[查看本(http://stackoverflow.com /問題/ 33877134/errorexecution失敗的換任務androidtransformclassesandresourceswithprogua) –

回答

0

您可以將minifyEnabled設置爲true並使用任意數量的庫。只需要記住一件事就可以在proguard-rules.pro文件中添加每個庫的proguard規則。檢查改進程序here

最後添加一個proguard-rules.pro供您參考,這是爲即時處理項目。 (您可能還需要通知的ProGuard排除您的POJO類。檢查例子)

# Add project specific ProGuard rules here. 
# By default, the flags in this file are appended to flags specified 
# in /Users/yogeshmalpani/Library/Android/sdk/tools/proguard/proguard-android.txt 
# You can edit the include path and order by changing the proguardFiles 
# directive in build.gradle. 
# 
# For more details, see 
# http://developer.android.com/guide/developing/tools/proguard.html 

# Add any project specific keep options here: 
-dontwarn com.squareup.okhttp.** 
-keep class com.pushwoosh.** { *; } 
-keep class com.arellomobile.** { *; } 
-dontwarn com.pushwoosh.** 
-dontwarn com.arellomobile.** 
-dontwarn butterknife.internal.** 
-keep class **$$ViewInjector { *; } 
-keepnames class * { @butterknife.InjectView *;} 
-keepattributes *Annotation*,EnclosingMethod,Signature,SourceFile,LineNumberTable 
-keepnames class com.fasterxml.jackson.** { *; } 
-dontwarn com.fasterxml.jackson.databind.** 
-keep class org.codehaus.** { *; } 
-keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility { 
public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; } 
# My POJO class directory 
-keep public class com.app_name.model.pojo.** { 
    public void set*(***); 
    public *** get*(); 
    public protected private *; 
} 
# If your project uses WebView with JS, uncomment the following 
# and specify the fully qualified class name to the JavaScript interface 
# class: 
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { 
# public *; 
#} 
0

我認爲你正在使用改型2,

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