2015-12-18 91 views
0

我正在嘗試爲我的應用程序配置proguard。一切工作正常,直到我啓用了構建文件中的minifyEnabled。之後是說下面的錯誤:無法爲android配置proguard

Error:Execution failed for task ':app:shrinkReleaseMultiDexComponents'. 
> java.io.IOException: The output jar [E:\androidStudioProjects\name\app\build\intermediates\multi-dex\release\componentClasses.jar] must be specified after an input jar, or it will be empty. 

我gradle這個文件是

apply plugin: 'com.android.application' 
android { 
    compileSdkVersion 22 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     applicationId "com.name.activity" 
     minSdkVersion 13 
     targetSdkVersion 22 
     versionCode 29 
     versionName "3.0.3" 
     multiDexEnabled true 
    } 
    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:support-v4:22.+' 
    compile 'com.android.support:appcompat-v7:22.1.1' 
    compile 'com.google.android.gms:play-services:7+' 
    compile project(':googlemapssdkm4b_lib') 
    compile 'com.android.support:multidex:1.0.0' 
    compile 'com.github.johnkil.android-robototextview:robototextview:2.4.0' 
    compile 'com.android.support:recyclerview-v7:22.2.+' 
    compile project(':volley') 
    compile 'com.android.support:design:22.2.0' 
    compile 'com.appyvet:materialrangebar:1.0' 

} 

我proguard-rules.pro文件

# This is a configuration file for ProGuard. 
# http://proguard.sourceforge.net/index.html#manual/usage.html 
-dontusemixedcaseclassnames 
-dontskipnonpubliclibraryclasses 
-verbose 

# Optimization is turned off by default. Dex does not like code run 
# through the ProGuard optimize and preverify steps (and performs some 
# of these optimizations on its own). 
#-dontoptimize 
#-dontpreverify 

# If you want to enable optimization, you should include the 
# following: 
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/* 
-optimizationpasses 5 
-allowaccessmodification 
# 
# Note that you cannot just include these flags in your own 
# configuration file; if you are including this file, optimization 
# will be turned off. You'll need to either edit this file, or 
# duplicate the contents of this file and remove the include of this 
# file from your project's proguard.config path property. 

-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 public class * extends com.actionbarsherlock.app.SherlockListFragment 
-keep public class * extends com.actionbarsherlock.app.SherlockFragment 
-keep public class * extends com.actionbarsherlock.app.SherlockFragmentActivity 
-keep public class * extends android.app.Fragment 
-keep public class com.android.vending.licensing.ILicensingService 

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native 
-keepclasseswithmembernames class * { 
native <methods>; 
} 

-keep public class * extends android.view.View { 
public <init>(android.content.Context); 
public <init>(android.content.Context, android.util.AttributeSet); 
public <init>(android.content.Context, android.util.AttributeSet, int); 
public void set*(...); 
} 

-keepclasseswithmembers class * { 
public <init>(android.content.Context, android.util.AttributeSet); 
} 

-keepclasseswithmembers class * { 
public <init>(android.content.Context, android.util.AttributeSet, int); 
} 

-keepclassmembers class * extends android.app.Activity { 
public void *(android.view.View); 
} 

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations 
-keepclassmembers enum * { 
public static **[] values(); 
public static ** valueOf(java.lang.String); 
} 

-keep class * implements android.os.Parcelable { 
public static final android.os.Parcelable$Creator *; 
} 

-keepclassmembers class **.R$* { 
public static <fields>; 
} 

-keep class android.support.v4.app.** { *; } 
-keep interface android.support.v4.app.** { *; } 
-keep class com.actionbarsherlock.** { *; } 
-keep interface com.actionbarsherlock.** { *; } 
# The support library contains references to newer platform versions. 
# Don't warn about those in case this app is linking against an older 
# platform version. We know about them, and they are safe. 
-dontwarn android.support.** 
-dontwarn com.google.ads.** 

請幫我在這..

回答

0

我花了很長時間才弄清楚,但正如我所猜測的,這完全是關於Proguard的配置。

我開始挖掘控制檯中的警告,並意識到Proguard找不到一些引用。因此,將它們作爲-dontwarn添加到proguard配置文件解決了問題。

在我的情況下,我不得不忽略下面的包;

-dontwarn java.lang.invoke** 
-dontwarn org.apache.lang.** 
-dontwarn org.apache.commons.** 
-dontwarn com.nhaarman.** 
-dontwarn se.emilsjolander.** 
+0

嗨Harshad。感謝回覆 。但上面的解決方案不適合我 –