在Android应用程序中使用MultiDex运行ProGuard两次,第二次使用Warnings / Notes?

我在我的
Android应用程序中使用MultiDex和ProGuard.当我运行我的应用程序时,事实证明proguard运行了两次.以下是proguard运行之后的任务:

:app:transformClassesAndResourcesWithProguardForRelease
ProGuard, version 5.2.1
...
Initializing...
Shrinking...
Obfuscating...
Writing output...

然后:

:app:transformClassesWithMultidexlistForRelease
ProGuard, version 5.2.1

这是我的应用程序的build.gradle文件:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.20.1'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "de.majestella"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 3
        versionName "1.0.1"

        // Enabling multidex support.
        multiDexEnabled true
    }

    dexOptions {
        incremental true
        javaMaxHeapSize "2g"
    }


    buildTypes {
        debug {
            debuggable true

            // ProGuard
            minifyEnabled false
        }
        release {
                signingConfig signingConfigs.release

                debuggable false

                // ProGuard
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'),
                        'proguard-rules.pro', 'proguard-guava.pro', 'proguard-square-picasso.pro',
                        'proguard-crashlytics.pro', 'proguard-google-analytics.pro'

       }

    }

}

repositories {
    mavenCentral()
    maven {
        name = "sonatype"
        url = "https://oss.sonatype.org/content/repositories/snapshots/"
    }
    maven {
        name = "sonatypeGoogle"
        url = "https://oss.sonatype.org/content/repositories/google-snapshots/"
    }
    flatDir {
        dirs 'libs'
    }
    maven { url 'https://maven.fabric.io/public' }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'


    compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
        transitive = true;
    }

    compile 'com.android.support:multidex:1.0.1'

    compile 'com.google.android.gms:play-services-analytics:8.1.0'
    compile "com.google.android.gms:play-services:8.1.0"

}

在第一个proguard运行之后(即,在:app:transformClassesAndResourcesWithProguardForRelease之后)我在写入输出后得到以下警告,因此proguard本身在我的规则下工作正常:

Warning: can't write resource [fabric/com.crashlytics.sdk.android.answers.properties] (Duplicate zip entry [fabric/com.crashlytics.sdk.android.answers.properties])
Warning: can't write resource [fabric/com.crashlytics.sdk.android.beta.properties] (Duplicate zip entry [fabric/com.crashlytics.sdk.android.beta.properties])
Warning: can't write resource [fabric/com.crashlytics.sdk.android.crashlytics-core.properties] (Duplicate zip entry [fabric/com.crashlytics.sdk.android.crashlytics-core.properties])
Warning: can't write resource [fabric/com.crashlytics.sdk.android.crashlytics.properties] (Duplicate zip entry [fabric/com.crashlytics.sdk.android.crashlytics.properties])
Warning: can't write resource [fabric/io.fabric.sdk.android.fabric.properties] (Duplicate zip entry [fabric/io.fabric.sdk.android.fabric.properties])

当第二个proguard运行发生之后:app:transformClassesWithMultidexlistForRelease我得到以下内容:

Note: android.support.design.widget.CoordinatorLayout calls 'Class.getAnnotation'
Note: com.google.ads.mediation.MediationServerParameters calls 'Field.getAnnotation'
Note: com.google.common.eventbus.AnnotatedSubscriberFinder calls 'Method.getAnnotation'
Note: com.google.common.reflect.Invokable$MethodInvokable calls 'Method.getParameterAnnotations'
Note: d.a.a.a.c calls 'Class.getAnnotation'
Note: d.a.a.a.i calls 'Class.getAnnotation'
Note: android.support.v4.app.ak calls 'Field.getType'
Note: com.google.android.gms.internal.zzsf calls 'Field.getType'
...

这很奇怪,因为在第一次比赛中,由于我的规则,我没有得到这样的警告/注释.

以下是我的ProGuard规则:

-keep class com.google.common.io.Resources {
    public static <methods>;
}
-keep class com.google.common.collect.Lists {
    public static ** reverse(**);
}
-keep class com.google.common.base.Charsets {
    public static <fields>;
}
-keep class com.google.common.collect.MapMakerInternalMap$ReferenceEntry
-keep class com.google.common.cache.LocalCache$ReferenceEntry

-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue
-keepattributes SourceFile,LineNumberTable,*Annotation*
-keep class com.crashlytics.android.**



-dontwarn com.squareup.okhttp.**

-dontnote org.apache.http.conn.**
-dontnote org.apache.http.params.**
-dontnote android.net.http.**

-dontnote **ILicensingService
-dontnote com.android.vending.billing.IInAppBillingService


-dontwarn com.google.auto.factory.**

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod


-dontnote android.support.**
-dontnote com.google.common.util.concurrent.**
-dontnote com.squareup.okhttp.**

-keep class org.jsoup.** { *; }
-keeppackagenames org.jsoup.nodes
-keep class com.google.common.cache.Striped64 { *; }
-keep class com.google.common.** { *; }
-keep class com.daimajia.slider.** { *; }


-dontnote org.jsoup.**
-dontnote com.google.common.**
-keep class com.squareup.picasso.** { *; }
-keep class com.google.android.gms.** { *; }
-keep class com.google.ads.** { *; }
-keep class com.lorentzos.** { *; }
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

-dontnote com.google.android.gms.maps.internal.CreatorImpl

-keep class com.mikepenz.iconics.** { *; }

在我看来,第二次ProGuard运行并没有使用我的proguard规则.

编辑:这是gradlew -q任务的结果–all:https://gist.github.com/confile/2a15d80980214656f4f1

为什么第二个Proguard运行会引发错误,我该如何解决?

最佳答案 这似乎是android gradle插件问题.见这
https://www.google.co.kr/url?sa=t&source=web&rct=j&url=https://groups.google.com/forum/m/%23!topic/adt-dev/iS_lyRH8hL8&ved=0ahUKEwiP7cP-nMHJAhXLp5QKHX3qBuwQFggdMAI&usg=AFQjCNF4ZuCA79SeCltd8kBIzArzeBbKsQ&sig2=UFqfkY_By7z1rCW4SwmQZw

点赞