【问题标题】:Unable to generate signed apk with proguard无法使用 proguard 生成签名的 apk
【发布时间】:2017-02-19 08:25:37
【问题描述】:

当我尝试生成启用了 proguard 的签名 apk 时出现以下错误。

Error:Uncaught translation error: com.android.dx.cf.code.SimException: com.android.dx.rop.cst.CstMethodRef cannot be cast to com.android.dx.rop.cst.CstInterfaceMethodRef
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
<a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

这就是我正在使用/正在做的事情:

  1. Android 工作室 2.2
  2. 播放服务版本 9.6.1
  3. proguard-rules.pro

    • dontwarn okio.
    • dontwarn retrofit2.Platform$Java8
    • keep public class com.google.android.gms.
    • dontwarn com.google.android.gms.
    • keepattributes InnerClasses,EnclosingMethod
  4. gradle(应用程序)

    defaultConfig {
        applicationId "com.something.something"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 3
        versionName "3.0"
    
        // Enabling multidex support.
        multiDexEnabled true
    
        testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    
  5. 我正在使用的库:

    • com.radiusnetworks:proximitykit-android:0.+@aar
    • com.squareup.retrofit2:retrofit:2.0.2
    • com.google.firebase:firebase-messaging:9.6.1

【问题讨论】:

    标签: android google-play-services proguard android-multidex signed-apk


    【解决方案1】:

    基于此SO answer,只要您不需要任何特殊的 ProGuard 配置,下面的代码就应该可以工作。

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt')
        }
    }
    

    如果您这样做,请使用您原来的 proguardFiles 条目并创建文件 /Users/franek/Documents/Android_Studio_Melange/app/proguard-rules.txt,然后将您的自定义规则放入此文件中。

    这个thread 也可能有帮助。将以下行添加到proguard-rules.pro 文件中,以解决使用Proguard (Minify Enabled = true) 无法生成签名APK 的问题。

    保留类 org.apache.http.**
    保留类 android.net.http.**
    不要警告 com.google.android.gms.**

    【讨论】:

    • 我曾经必须设置 minifyEnabled = false 才能工作!
    猜你喜欢
    • 1970-01-01
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 2020-06-29
    相关资源
    最近更新 更多