2017-03-05 88 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