Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I upgrade my android project to 24 SDK version.

But I got error in Proguard path of build:

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.

My proguard.cfg file:

-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 in project:

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

Build.gradle in app:

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'

This configs work fine on 22 android SDK, but after update to 24 got error.

I try add next but not success:

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

What is my error and what is a solution?

Why don't you use proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')? – tynn Jun 26, 2016 at 23:18 Can you try to keep the following classes such that they are not getting optimized: -keep,allowshrinking class com.google.android.gms.iid.** { *; } – T. Neidhart Jun 27, 2016 at 10:32

I ended up with the following proguard options:

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

This is caused by buildtools working with 8.4 version of google play services. I tried excluding the particular class from optimization with -keep, but it didn't work. I ended up with migrating to google play services 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')

Try using version 9.2.1; it seems they have fixed a proguard issue. Based on the release notes.

Refer link: https://developers.google.com/android/guides/releases

If you don't feel like bumping the play services just yet, you can also turn off the following optimizations in ProGuard, e.g.

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

Obviously, this might mean a performance hit, so use judiciously.

Try using version 9.2.1; it seems they have fixed a proguard issue. Based on the release notes.

Refer link: https://developers.google.com/android/guides/releases

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.