2

當我嘗試生成已啓用proguard的已簽名apk時,出現以下錯誤。無法使用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 Studio 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這個(APP)

    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:[email protected]
    • com.squareup.retrofit2:retrofit:2.0.2
    • com.google.firebase:firebase-messaging:9.6.1

回答

0

從這個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。**
dontwarn com.google.android.gms。**

+0

我曾經到設置minifyEnabled = false爲我的工作! – Eenvincible

相關問題