2016-06-26 92 views
3

我將我的android項目升級到24 SDK版本。評估指令時出現Proguard錯誤

但我在建的Proguard的路徑遇到錯誤:

Unexpected error while evaluating instruction: 
    Class  = [com/google/android/gms/iid/zzd] 
    Method  = [zzeC(Ljava/lang/String;)V] 
    Instruction = [11] invokevirtual #50 
    Exception = [java.lang.ArrayIndexOutOfBoundsException] (1) 
Unexpected error while performing partial evaluation: 
    Class  = [com/google/android/gms/iid/zzd] 
    Method  = [zzeC(Ljava/lang/String;)V] 
    Exception = [java.lang.ArrayIndexOutOfBoundsException] (1) 
Warning: Exception while processing task java.io.IOException: java.lang.ArrayIndexOutOfBoundsException: 1 
:PC:transformClassesAndResourcesWithProguardForDebug FAILED 

FAILURE: Build failed with an exception. 

我proguard.cfg文件:

-printmapping /build/proguard-mapping.txt 
-printusage /build/proguard-usage.txt 
-printseeds /build/proguard-seeds.txt 
-printconfiguration /build/proguard-configuration.txt 

-optimizationpasses 5 
-dontskipnonpubliclibraryclasses 
-dontskipnonpubliclibraryclassmembers 
#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 
-optimizations !class/unboxing/enum 
-allowaccessmodification 
-repackageclasses '' 
-keepattributes Signature 
-keepattributes SetJavaScriptEnabled 
-keepattributes JavascriptInterface 
-keepattributes InlinedApi 
-keepattributes SourceFile, LineNumberTable 
-keepattributes *Annotation* 

-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.preference.Preference 

-libraryjars /libs 

-dontwarn android.** 
-dontwarn com.android.** 
-dontwarn com.google.** 
-dontwarn okio.** 

-keep class com.google.** {*;} 
-keepclassmembers class com.google.** { *; } 

-keep class com.android.** {*;} 
-keepclassmembers class com.android.** { *; } 

-keep class okio.** {*;} 
-keepclassmembers class okio.** { *; } 

的build.gradle項目:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 
     classpath 'com.google.gms:google-services:3.0.0' 
    } 
} 

的build.gradle在應用程序中:

apply plugin: 'com.android.application' 
apply plugin: 'com.google.gms.google-services' 

buildscript { 
    repositories { 
     jcenter() 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 
    } 
} 

android { 
    compileSdkVersion 24 
    buildToolsVersion "24.0.0" 

    defaultConfig { 
     minSdkVersion 11 
     targetSdkVersion 24 
     signingConfig signingConfigs.release 
    } 

    buildTypes { 
     debug { 
      debuggable true 
      minifyEnabled true 
      signingConfig signingConfigs.release 
      proguardFile 'proguard.cfg' 
     } 
     release { 
      debuggable true 
      minifyEnabled true 
      signingConfig signingConfigs.release 
      proguardFile 'proguard.cfg' 
     } 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.google.android.gms:play-services-gcm:9.0.0' 
    compile 'com.android.support:support-v4:24.0.0' 
    compile 'com.android.support:appcompat-v7:24.0.0' 
} 

這配置工作很好22 android SDK,但更新到24後出現錯誤。

我嘗試添加下一個但不是成功:

-keep class com.google.android.gms.analytics.** 
-keep class com.google.analytics.tracking.** 
-dontwarn com.google.android.gms.analytics.** 
-dontwarn com.google.analytics.tracking.** 

什麼是我的錯誤,什麼是解決方案嗎?

+0

你爲什麼不使用'proguardFiles getDefaultProguardFile( 'proguard的-Android的optimize.txt')'? – tynn

+0

我嘗試了它,但沒有更改 –

+0

您可以嘗試保留以下類,以免它們得到優化:-keep,允許類com.google.android.gms.iid。** {*; } –

回答

1

這是由與8.4版本的谷歌播放服務工作的buildtools造成的。我嘗試用-keep從優化中排除特定的類,但它不起作用。我結束了遷移到Google Play服務9.0.2:

classpath 'com.android.tools.build:gradle:2.0.0' 
classpath 'com.google.gms:google-services:3.0.0' 

...

buildToolsVersion "24.0.0" 

...

// google play services 
compile ('com.google.android.gms:play-services-gcm:9.0.2') 
compile ('com.google.android.gms:play-services-analytics:9.0.2') 

...

0

如果你不感覺像碰撞只是播放服務,您還可以關閉以下優化在ProGuard中,例如

-optimizations !method/marking/private,!method/marking/static,!method/removal/parameter,!method/propagation/parameter

顯然,這可能意味着性能的下降,所以明智地使用。

2

我結束了以下proguard的選項:

# WORKAROUND for building project with GMS (google play services) 
-keep class com.google.android.gms.iid.zzd { *; } 
-keep class android.support.v4.content.ContextCompat { *; }