更新到Google Play服务11.8.0后,Proguard无法正常工作

时间:2018-01-02 10:17:52

标签: android google-play-services proguard android-proguard

将Google Play服务更新为11.8.0(从11.6.2开始)后,我的版本停止运行。

这就是我得到的:

  

计算堆栈大小时出现意外错误:     Class = [com / google / android / gms / internal / zzao]     方法= [zzf(Ljava / lang / String;)J]     Exception = [java.lang.IllegalArgumentException](在[com / google / android / gms / internal / zzao.zzf(Ljava / lang / String;)J]中指令[23] invokestatic#146之后,堆栈大小变为负数   FAILURE:构建因异常而失败。

我正在使用带有Gradle 4.4.1的Android Studio 3.0.1

我的应用build.gradle文件

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"

2 个答案:

答案 0 :(得分:16)

您不需要完全禁用优化,只需优化问题类。我遇到了同样的问题并通过在 proguard-rules.pro 文件中添加以下内容来解决这个问题:

-keep class com.google.android.gms.internal.** { *; }

答案 1 :(得分:1)

我有类似的问题。根据建议in this SO thread,您只需在build.gradle文件中添加以下行:

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

我还必须通过替换:

删除专业保护优化
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

通过

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