【问题标题】:Proguard error while evaluating instruction评估指令时出现 Proguard 错误
【发布时间】:2016-10-28 20:54:28
【问题描述】:

我将我的 android 项目升级到 24 SDK 版本。

但我在构建的 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.**

我的错误是什么?解决方法是什么?

【问题讨论】:

  • 你为什么不用proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
  • 我尝试过,但没有改变
  • 您能否尝试保留以下类以使其未得到优化:-keep,allowshrinking class com.google.android.gms.iid.** { *; }
  • @tome 不起作用 =(

标签: android build proguard


【解决方案1】:

我最终得到了以下 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 { *; }

【讨论】:

    【解决方案2】:

    这是由于 buildtools 使用 8.4 版本的 google play 服务造成的。我尝试使用 -keep 将特定类排除在优化之外,但它不起作用。我最终迁移到 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')
    

    ...

    【讨论】:

      【解决方案3】:

      尝试使用 9.2.1 版本;看来他们已经解决了一个proguard问题。基于发行说明。

      参考链接:https://developers.google.com/android/guides/releases

      【讨论】:

        【解决方案4】:

        如果你还不想影响播放服务只是,你也可以在 ProGuard 中关闭以下优化,例如

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

        显然,这可能意味着性能下降,因此请谨慎使用。

        【讨论】:

          【解决方案5】:

          尝试使用 9.2.1 版本;看来他们已经解决了一个proguard问题。基于发行说明。

          参考链接:https://developers.google.com/android/guides/releases

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-10-07
            • 2020-10-05
            • 1970-01-01
            • 2022-11-11
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-07-25
            相关资源
            最近更新 更多