尝试生成发布apk时出现Proguard错误

时间:2017-11-05 19:59:43

标签: android gradle android-gradle proguard android-proguard

我在尝试为应用程序生成release apk时遇到以下错误。

我搜索了各个地方的问题,但找不到任何可以帮助我的东西,我还搜索了所有依赖项的proguard规则,并将它们添加到proguard规则文件中,但添加这些也没有帮助(我后来删除了一些,因为他们没有帮助)。

生成调试apk时没有任何错误。

错误:

* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.

build.gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
compileSdkVersion 27
buildToolsVersion '27.0.0'
defaultConfig {
    applicationId "com.nrs.nsnik.notes"
    minSdkVersion 24
    targetSdkVersion 27
    versionCode 30
    versionName "2.9.3"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
    resConfigs "en"
    splits {
        abi {
            enable true
            reset()
            include "x86_64", "x86", "armeabi", "armeabi-v7a", "arm64-v8a", "mips"
            universalApk false
        }
        density{
            enable true
            reset()
            include "ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"
            //compatibleScreens 'small', 'normal', 'large', 'xlarge'
        }
    }
    javaCompileOptions {
        annotationProcessorOptions {
            arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
        }
    }
}
sourceSets {
    androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
buildTypes {
    debug{
        //applicationIdSuffix '.debug'
        //versionNameSuffix '-DEBUG'
        ext.alwaysUpdateBuildId = false
    }
    release {
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
dexOptions {
    javaMaxHeapSize "4g"
}
if (project.hasProperty('devBuild')) {
    splits.density.enable = false
    splits.abi.enable  = false
    aaptOptions {
        cruncherEnabled = false
    }
}
}

ext.abiCodes = ['armeabi': 3, 'armeabi-v7a': 4, 'arm64-v8a': 5, mips: 6, 'x86': 7, 'x86_64': 8]
ext.densityCodes = ['ldpi': 3,'mdpi': 4, 'hdpi': 5,'xhdpi': 6,'xxhdpi': 7,'xxxhdpi': 8]
import com.android.build.OutputFile

android.applicationVariants.all { variant ->
variant.outputs.each { output ->
    def baseAbiVersionCode = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
    def baseDensityVersionCode = project.ext.densityCodes.get(output.getFilter(OutputFile.DENSITY))
    if (baseAbiVersionCode != null && baseDensityVersionCode !=null) {
        output.versionCodeOverride = baseAbiVersionCode * 1000 + baseDensityVersionCode * 1000 + variant.versionCode
    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') { transitive = true }

//MULTI DEX
implementation 'com.android.support:multidex:1.0.2'

//APPCOMPAT LIBRARY
implementation 'com.android.support:appcompat-v7:27.0.0'

//RECYCLER VIEW
implementation 'com.android.support:recyclerview-v7:27.0.0'

//ANNOTATION SUPPORT LIBRARY
implementation 'com.android.support:support-annotations:27.0.0'

//DESIGN SUPPORT LIBRARY
implementation 'com.android.support:design:27.0.0'

//CONSTRAINT LAYOUT
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta3'

//CARD VIEW
implementation 'com.android.support:cardview-v7:27.0.0'

//PALETTE
implementation 'com.android.support:palette-v7:27.0.0'

//FINDBUGS JSR305
implementation 'com.google.code.findbugs:jsr305:3.0.2'

//FIRE BASE
implementation 'com.google.firebase:firebase-ads:11.4.2'
implementation 'com.google.android.gms:play-services-ads:11.4.2'

//RX JAVA & ANDROID
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.6'

//RX BINDING
implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-support-v4:2.0.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7:2.0.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-design:2.0.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-recyclerview-v7:2.0.0'

//CHROME CUSTOM TABS
implementation 'com.android.support:customtabs:27.0.0'

//TIMBER LOGGER
implementation 'com.jakewharton.timber:timber:4.6.0'

//GUAVA
implementation 'com.google.guava:guava:23.0'

//DAGGER 2
implementation 'com.google.dagger:dagger-android:2.12'
implementation 'com.google.dagger:dagger-android-support:2.12'
annotationProcessor 'com.google.dagger:dagger-compiler:2.12'

//BUTTER KNIFE
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

//GLIDE
implementation 'com.github.bumptech.glide:glide:4.2.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'

//ROLL BAR
implementation 'com.rollbar:rollbar-android:0.2.1'

//EVENT BUS
implementation 'org.greenrobot:eventbus:3.0.0'

//AUTO VALUE
compileOnly "com.google.auto.value:auto-value:1.5.2"
annotationProcessor "com.google.auto.value:auto-value:1.5.2"

//AUTO PARCEL
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'

//LEAK CANARY
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

//BLOCK CANARY
implementation 'com.github.markzhai:blockcanary-android:1.5.0'

//DART
implementation 'com.f2prateek.dart:dart:2.0.2'
annotationProcessor 'com.f2prateek.dart:dart-processor:2.0.2'

//HENSON
implementation 'com.f2prateek.dart:henson:2.0.2'
annotationProcessor 'com.f2prateek.dart:henson-processor:2.0.2'

//LIFE CYCLE EXTENSIONS
implementation "android.arch.lifecycle:extensions:1.0.0-rc1"

//LIFE CYCLE JAVA 8
implementation "android.arch.lifecycle:common-java8:1.0.0-rc1"

//LIVE DATA BACKGROUND TEST
testImplementation "android.arch.core:core-testing:1.0.0-rc1"

//LIVE DATA WITH REACTIVE STREAMS
implementation "android.arch.lifecycle:reactivestreams:1.0.0-rc1"

//ROOM
implementation "android.arch.persistence.room:runtime:1.0.0-rc1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-rc1"

//ROOM TEST MIGRATION
testImplementation "android.arch.persistence.room:testing:1.0.0-rc1"

//ROOM RxJAVA
implementation "android.arch.persistence.room:rxjava2:1.0.0-rc1"

//PAGING
implementation "android.arch.paging:runtime:1.0.0-alpha3"

//OK IO
implementation 'com.squareup.okio:okio:1.13.0'

//MOCKITO
testImplementation "org.mockito:mockito-core:2.11.0"

//JETBRAINS ANNOTATION
implementation 'org.jetbrains:annotations:13.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'

proguard-rules.pro

-optimizationpasses 5
-allowaccessmodification
-assumenosideeffects
-verbose
-keepattributes Signature

-assumenosideeffects class timber.log.Timber {
 public static *** d(...);
 public static *** i(...);
 public static *** v(...);
}

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}

-libraryjars <java.home>/lib/rt.jar

-dontwarn com.f2prateek.dart.internal.**
-keep class **$$ExtraInjector { *; }
-keepclasseswithmembernames class * {
@com.f2prateek.dart.* <fields>;
}
-keep class **Henson { *; }
-keep class **$$IntentBuilder { *; }

-keep class * implements android.arch.lifecycle.GeneratedAdapter {<init>(...);}

-keepclasseswithmembers class * implements android.arch.lifecycle.GenericLifecycleObserver {
<init>(...);
}
-keepclassmembers class android.arch.lifecycle.Lifecycle$* { *; }
-keepclassmembers class * {
@android.arch.lifecycle.OnLifecycleEvent *;
}
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
<init>(...);
}

-dontwarn okio.**

-dontwarn javax.annotation.**

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

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

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

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

-dontwarn org.mockito.**

1 个答案:

答案 0 :(得分:1)

我刚刚通过添加以下ProGuard规则解决了这个问题:

-dontwarn com.google.auto.value.AutoValue
-dontwarn com.google.auto.value.AutoValue$Builder

此问题与版本1.5中引入的AutoValue批注的更改保留策略有关。