Proguard 重复邮编条目

Posted

技术标签:

【中文标题】Proguard 重复邮编条目【英文标题】:Proguard Duplicate Zip Entry 【发布时间】:2017-08-10 21:14:14 【问题描述】:

我正在尝试通过 Proguard 运行我的 android 应用程序,但是这一直出现:

Warning:Exception while processing task java.io.IOException: Can't write [C:\Users\Aliaksei\AndroidStudioProjects\SignOutSystem\app\build\intermediates\transforms\proguard\debug\jars\3\1f\main.jar] (Can't read [D:\Users\Aliaksei\.android\build-cache\f7a6034d02d095f18cc21950f131d07fa78b41c0\output\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [android/support/v4/os/j.class == classes.jar:android/support/v4/os/ResultReceiver$MyResultReceiver.class]))

我知道这意味着 android.support.v4 在某处被声明了两次,所以我尝试将 exclude group: 'com.android.support', module: 'support-v4' 添加到可能包含它的任何可能依赖项中,但是即使在干净和重建。

我想我一定是在某个地方遗漏了一个依赖项,我继续将它添加到所有内容中(Overkill),但这仍然没有奏效。

四处搜索,我在类似的帖子中找到了这个 sn-p,并将其也添加到了 android 部分:

packagingOptions 
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'

我的想法已经用完了,寻找答案似乎把我带到了我已经尝试过的事情上。我有什么遗漏吗?

app build.gradle(一团糟,上面有所有的黑客):

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
//apply plugin: 'com.getkeepsafe.dexcount'

android 
    compileSdkVersion 23
    buildToolsVersion '25.0.0'

    defaultConfig 
        applicationId "com.aliakseipilko.signoutsystem"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    
    buildTypes 
        release 
            minifyEnabled true
            shrinkResources true
            zipAlignEnabled true
            proguardFile 'proguard-signoutsystem.txt'
        
        debug 
            minifyEnabled true
            shrinkResources false
            zipAlignEnabled true
            proguardFile 'proguard-signoutsystem.txt'
        
    
    packagingOptions 
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    


//dexcount 
//    format = "list"
//    includeClasses = false
//    includeFieldCount = true
//    includeTotalMethodCount = true
//    orderByMethodCount = true
//    verbose = false
//    maxTreeDepth = Integer.MAX_VALUE
//    teamCityIntegration = false
//    enableForInstantRun = false
//

repositories 
    maven 
        url "https://jitpack.io"
    


dependencies 
    compile('com.google.api-client:google-api-client-android:1.22.0') 
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile('com.google.apis:google-api-services-sheets:v4-rev19-1.22.0') 
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile('com.google.android.gms:play-services-identity:9.2.0') 
        exclude group: 'com.google.guava'
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile ('com.google.android.gms:play-services-auth:9.2.0') 
        exclude group: 'com.android.support', module: 'support-v4'
    

    compile ('com.android.support:appcompat-v7:23.4.0') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile ('com.android.support:design:23.4.0') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile 'com.android.support:support-v4:23.4.0'
    compile ('com.android.support:percent:23.4.0') 
        exclude group: 'com.android.support', module: 'support-v4'
    

    compile ('com.squareup.okhttp3:okhttp:3.3.1') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile ('com.squareup.okhttp3:logging-interceptor:3.3.1') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile ('com.squareup.okio:okio:1.8.0') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile ('com.squareup.picasso:picasso:2.5.2') 
        exclude group: 'com.android.support', module: 'support-v4'
    

    compile ('net.sf.biweekly:biweekly:0.4.6') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile ('com.github.tibolte:agendacalendarview:1.0.4') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile ('com.7heaven.widgets:segmentcontrol:1.14') 
        exclude group: 'com.android.support', module: 'support-v4'
    

    compile ('com.survivingwithandroid:weatherlib:1.6.0') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    compile 'com.survivingwithandroid:weatherlib_okhttpclient:1.6.0'

    compile files('libs/FDxSDKProAndroid.jar')

    debugCompile ('com.squareup.leakcanary:leakcanary-android:1.5') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    releaseCompile ('com.squareup.leakcanary:leakcanary-android-no-op:1.5') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    testCompile ('com.squareup.leakcanary:leakcanary-android-no-op:1.5') 
        exclude group: 'com.android.support', module: 'support-v4'
    

    compile ('com.jakewharton:butterknife:8.5.1') 
        exclude group: 'com.android.support', module: 'support-v4'
    
    annotationProcessor ('com.jakewharton:butterknife-compiler:8.5.1') 
        exclude group: 'com.android.support', module: 'support-v4'
    

项目build.gradle:

buildscript 
    repositories 
        jcenter()
    
    dependencies 
        classpath 'com.android.tools.build:gradle:2.4.0-alpha1'
        classpath "io.realm:realm-gradle-plugin:3.0.0"
//        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.5.5'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    


allprojects 
    repositories 
        jcenter()
        flatDir 
            dirs 'libs'
        
    


task clean(type: Delete) 
    delete rootProject.buildDir

Proguard 规则:

#DEBUGGING
#-dontobfuscate
#-dontoptimize
###############
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-adaptresourcefilenames

-keep class com.aliakseipilko.signoutsystem.**  *; 
-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
-keep public class com.android.vending.billing.IInAppBillingService
-keep public class * extends android.view.View 
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);

-keepclasseswithmembers class * 
    public <init>(android.content.Context, android.util.AttributeSet);

-keepclasseswithmembers class * 
    public <init>(android.content.Context, android.util.AttributeSet, int);

-keepclassmembers class * extends android.content.Context 
    public void *(android.view.View);
    public void *(android.view.MenuItem);

-keepclassmembers enum * 
    public static **[] values();
    public static ** valueOf(java.lang.String);


-dontwarn sun.misc.Unsafe

-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-dontwarn biweekly.io.**
-dontwarn com.github.tibolte.**

-keep class com.github.tibolte.**
-keep class okio.**
-keep class biweekly.io.**
-keep class com.squareup.okhttp.**
-keep class SecuGen.FDxSDKPro.**
-keep class com.survivingwithandroid.**

-keep class android.support.v4.app.**  *; 
-keep interface android.support.v4.app.**  *; 
-dontwarn android.support.**

-keep public class android.support.v7.widget.**  *; 
-keep public class android.support.v7.internal.widget.**  *; 
-keep public class android.support.v7.internal.view.menu.**  *; 

-keep public class * extends android.support.v4.view.ActionProvider 
    public <init>(android.content.Context);


-keepclasseswithmembernames class * 
    native <methods>;


-keep class * implements android.os.Parcelable 
  public static final android.os.Parcelable$Creator *;


-keep class *.R

-keepclasseswithmembers class **.R$* 
    public static <fields>;


# Retain generated class which implement Unbinder.
-keep public class * implements butterknife.Unbinder  public <init>(**, android.view.View); 

# Prevent obfuscation of types which use ButterKnife annotations since the simple name
# is used to reflectively look up the generated ViewBinding.
-keep class butterknife.*
-keepclasseswithmembernames class *  @butterknife.* <methods>; 
-keepclasseswithmembernames class *  @butterknife.* <fields>; 

任何帮助将不胜感激。

【问题讨论】:

【参考方案1】:

问题是butterknife 编译时使用了更高的支持版本(25.1.0),因此您可能需要降级butterknife 或将所有支持库移至25.1.0

这里我已将butterknife 降级为8.0.1

dependencies 
    compile('com.google.api-client:google-api-client-android:1.22.0') 
        exclude module: 'httpclient'
    
    compile('com.google.apis:google-api-services-sheets:v4-rev19-1.22.0') 
        exclude module: 'httpclient'
    

    compile 'com.google.android.gms:play-services-identity:9.2.0'
    compile 'com.google.android.gms:play-services-auth:9.2.0'

    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:percent:23.4.0'

    compile 'com.squareup.okhttp3:okhttp:3.3.1'
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
    compile 'com.squareup.okio:okio:1.8.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'net.sf.biweekly:biweekly:0.4.6'
    compile 'com.github.tibolte:agendacalendarview:1.0.4'
    compile 'com.7heaven.widgets:segmentcontrol:1.14'
    compile 'com.survivingwithandroid:weatherlib:1.6.0'
    compile 'com.survivingwithandroid:weatherlib_okhttpclient:1.6.0'
    compile files('libs/FDxSDKProAndroid.jar')
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
    testCompile('com.squareup.leakcanary:leakcanary-android-no-op:1.5')

    compile 'com.jakewharton:butterknife:8.0.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'

然后在你的proguard.pro 处理警告:

 -keep class com.fasterxml.**  *; 
 -dontwarn com.fasterxml.**

 -keep class biweekly.io.json.**  *; 
 -dontwarn biweekly.io.json.**

 -dontwarn java.lang.invoke**

 -dontwarn sun.misc.Unsafe

 -dontwarn okio.**

请注意,我还启用了 multidex 以成功构建:我已将 multiDexEnabled true 添加到 defaultConfig

【讨论】:

以上是关于Proguard 重复邮编条目的主要内容,如果未能解决你的问题,请参考以下文章

带有重复 Zip 输入错误的 Proguard

Proguard:有 210 个重复的类定义?

proguard 注意:库类的重复定义 [javax.annotation.PostConstruct]

使用 ProGuard 和 Android 应用程序时资源重复

解决 ProGuard 中的“库类的重复定义”

如何在android studio中启用proguard? [重复]