15

After updating Google Play Services to 11.8.0 (from 11.6.2) my builds stop working.

This is what I got:

Unexpected error while computing stack sizes: Class = [com/google/android/gms/internal/zzao] Method = [zzf(Ljava/lang/String;)J] Exception = [java.lang.IllegalArgumentException] (Stack size becomes negative after instruction [23] invokestatic #146 in [com/google/android/gms/internal/zzao.zzf(Ljava/lang/String;)J]) FAILURE: Build failed with an exception.

I'm using Android Studio 3.0.1 with Gradle 4.4.1

My app build.gradle file

buildscript {
    repositories {
        maven { url "https://maven.fabric.io/public" }
    }

    dependencies {
        classpath "io.fabric.tools:gradle:1.25.1"
    }
}

repositories {
    maven { url "https://maven.fabric.io/public" }
}

apply plugin: "com.android.application"
apply plugin: "io.fabric"
apply plugin: "let"
apply plugin: "realm-android"

android {
    compileSdkVersion project.androidSDKVersion
    buildToolsVersion("$androidBuildToolsVersion")

    defaultConfig {
        versionCode project.versionCode
        versionName project.versionName

        minSdkVersion project.androidMinSdkVersion
        targetSdkVersion project.androidTargetSdkVersion

        vectorDrawables.useSupportLibrary = true
        resConfigs "pl"
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources false
            crunchPngs false
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro", "proguard-fresco.pro"
            signingConfig signingConfigs.release
        }
        debug {
            ext.enableCrashlytics = false
            ext.alwaysUpdateBuildId = false
        }
    }

    flavorDimensions "tier", "minApi"

    productFlavors {
        minApi21 {
            minSdkVersion project.androidMinDevSdkVersion
            dimension "minApi"
        }

        minApi16 {
            minSdkVersion project.androidMinSdkVersion
            dimension "minApi"
        }

        dev {
            multiDexEnabled true
            dimension "tier"
        }

        prod {
            multiDexEnabled false
            dimension "tier"
        }
    }

    variantFilter { variant ->
        def names = variant.flavors*.name

        if (names.contains("prod") && names.contains("minApi21")) {
            setIgnore(true)
        }
    }

    applicationVariants.all { variant ->
        appendVersionNameVersionCode(variant, defaultConfig)
    }

    lintOptions {
        checkReleaseBuilds false
        textReport true
        textOutput "stdout"
        fatal "UnusedResources"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    debugImplementation("com.android.support:multidex:$multidexVersion")

    implementation("com.android.support:support-fragment:$androidSupportVersion")
    implementation("com.android.support:support-annotations:$androidSupportVersion")
    implementation("com.android.support:appcompat-v7:$androidSupportVersion")
    implementation("com.android.support:design:$androidSupportVersion")
    implementation("com.android.support:recyclerview-v7:$androidSupportVersion")
    implementation("com.android.support:cardview-v7:$androidSupportVersion")
    implementation("com.android.support:customtabs:$androidSupportVersion")
    implementation("com.android.support.constraint:constraint-layout:$constraintLayoutVersion")
    implementation("com.android.installreferrer:installreferrer:$installReferrerVersion")

    implementation("com.google.android.gms:play-services-analytics:$playServicesVersion")
    implementation("com.google.android.gms:play-services-location:$playServicesVersion")
    implementation("com.google.android.gms:play-services-ads:$playServicesVersion")
    implementation("com.google.android.gms:play-services-auth:$playServicesVersion")

    implementation("com.google.firebase:firebase-core:$playServicesVersion")
    implementation("com.google.firebase:firebase-messaging:$playServicesVersion")
    implementation("com.google.firebase:firebase-config:$playServicesVersion")
    implementation("com.google.firebase:firebase-auth:$playServicesVersion")
    implementation("com.google.firebase:firebase-invites:$playServicesVersion")

    (...) // I had removed other dependencies from the list
}

def appendVersionNameVersionCode(variant, defaultConfig) {
    variant.outputs.all { output ->

        def versionCode = android.defaultConfig.versionCode

        output.versionCodeOverride = versionCode
        outputFileName = "${rootProject.name}-${variant.name}-${variant.versionName}-${versionCode}.apk"
    }
}

apply plugin: "com.google.gms.google-services"
PiotrWpl
  • 195
  • 1
  • 8

2 Answers2

17

You don't need to disable optimization entirely, just optimization on the problem class. I had the same issue and got around it by adding the following to the proguard-rules.pro file:

-keep class com.google.android.gms.internal.** { *; }
jnp
  • 186
  • 2
  • That was enough for me to compile the project. I wasn't needed to use proguard-android.txt instead of proguard-android-optimize.txt or extra lines in build.gradle like debuggable false & useProguard true – PiotrWpl Jan 11 '18 at 08:11
  • Just like @PiotrWpl said: there is no need to switch back from optimize Proguard setting, just add keep for the internal GMS classes in the setting. – racs Apr 29 '18 at 07:32
2

I have a similar issue. As suggested in this SO thread you just need to add these lines in your build.gradle file :

...
release {
   debuggable false
   useProguard true
   ...
}
...

I also had to remove the pro guard optimization by replacing :

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

by

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
sonic
  • 1,894
  • 1
  • 18
  • 22
  • I faced the exact same issue. Your solution worked. I used these configurations: debug { debuggable true minifyEnabled false useProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } release { debuggable false minifyEnabled true useProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } – Noel Chew Jan 10 '18 at 10:37
  • 1
    This is not needed, although it solves the issue, but your binary won't be optimized by Proguard. – racs Apr 29 '18 at 07:33