错误使用proguard创建签名的apk

时间:2017-06-29 12:10:10

标签: android proguard

我正在尝试使用proguard创建一个已签名的apk。 发生错误:

Warning: Exception while processing task java.io.IOException: Can not write [C: \ Android \ App \ Project \ app \ build \ intermediates \ transforms \ proguard \ release \ jars \ 3 \ 1f \ main.jar] (Can 'T read [C: \ users \ user \ .gradle \ caches \ modules-2 \ files-2.1 \ com.google.code.gson \ gson \ 2.7 \ 751f548c85fa49f330cecbb1875893f971b33c4e \ gson-2.7.jar (;;;;;; **. Class)] (Duplicate zip entry [com / google / a / a / a.class == gson-2.7.jar: com / google / gson / annotations / Expose.class]))
Error: Execution failed for task ': app: transformClassesAndResourcesWithProguardForRelease'.
Job failed, see logs for details

我配置的proguard-rules.pro文件

-keepattributes Signature
-keep class sun.misc.Unsafe { *; }
-keep class com.exp.data.** { *; }
-dontwarn com.google.common.**
-dontwarn com.google.gson.**
-dontwarn retrofit2.converter.gson.**
-dontwarn retrofit2.Platform$Java8
-dontwarn okio.**
-dontwarn org.apache.commons.io.FilenameUtils
-keep class okio.**

为什么会出现错误?

我正在使用build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    defaultConfig {
        applicationId "ru.vintegra.sale"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 41
        versionName '1.41'
        multiDexEnabled true
    }
    dexOptions {
        javaMaxHeapSize "4g" //specify the heap size for the dex process
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }
}    
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v13:25.3.1'
    compile 'com.microsoft.azure:azure-mobile-services-android-sdk:2.0.3'
    compile 'com.google.android.gms:play-services-location:11.0.1'
    compile 'com.google.android.gms:play-services-maps:11.0.1'
    compile 'com.google.android.gms:play-services-vision:11.0.1'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.retrofit2:converter-scalars:2.1.0'
    compile 'com.squareup.okhttp3:okhttp:3.4.2'
}

在我的项目中只有一个文件proguard-android.txt-2.3.3。 In my project only one file proguard-android.txt-2.3.3.

1 个答案:

答案 0 :(得分:0)

您可以尝试以下代码段:

########### OkHttp3 ###########

-keepattributes Signature

-keepattributes *Annotation*

-keep,includedescriptorclasses class okhttp3.** { *; }

-keep interface okhttp3.** { *; }

-dontwarn okhttp3.**

-dontnote okhttp3.**

######### OkHttp3 end #########

########### OkHttp URL Connection ###########

-keep class com.squareup.okhttp3.** { *; }

-keep interface com.squareup.okhttp3.** { *; }

-dontwarn com.squareup.okhttp3.**

-dontnote com.squareup.okhttp3.**

########### OkHttp URL Connection end ###########

-keep class com.google.android.gms.**

-keepclassmembers class com.google.android.gms.** {
    *;
 }

-keep class com.google.gson.**

-keepclassmembers class com.google.gson.** {
    *;
 }