当启用minify时processig任务异常

时间:2019-01-26 17:47:52

标签: android proguard minify android-proguard

这个问题很容易解释,我出错了

  

处理任务java.io.IOException时发生异常:java.lang.ArrayIndexOutOfBoundsException:4

在构建APK时。最初,我没有启用minify,但是它起作用了(但是产生了NoClassFoundError)。这就是为什么我在build.gradle文件中启用了minify的原因。最初,我收到了很多来自职业警卫的警告,因此我使用-dontwarn忽略了所有警告。 忽略所有警告后,我得到了上述异常。我不知道出了什么问题。在这里,我同时添加了gradle文件和proguard内容。

build.gradle

android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.plumelabs.air"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary true
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
    debug{
        //multiDexKeepProguard file('multidex-config.pro')
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    release {
        multiDexKeepProguard file('multidex-config.pro')
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-    core:3.0.2'

implementation 'com.android.support:multidex:1.0.0'

implementation 'com.google.android.gms:play-services-auth:16.0.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'

// https://mvnrepository.com/artifact/com.github.doctoror.geocoder/library
implementation group: 'com.github.doctoror.geocoder', name: 'library', version: '1.3.0'


implementation group: 'io.fabric.sdk.android', name: 'fabric', version: '1.4.2'
implementation 'io.nlopez.smartlocation:library:3.3.3'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'

implementation 'com.facebook.android:facebook-core:[4,5)'
implementation 'com.facebook.android:facebook-login:[4,5)'
/*implementation 'com.facebook.android:facebook-share:[4,5)'
implementation 'com.facebook.android:facebook-places:[4,5)'
implementation 'com.facebook.android:facebook-messenger:[4,5)'
implementation 'com.facebook.android:facebook-applinks:[4,5)'*/

implementation 'com.google.firebase:firebase-core:16.0.6'
// implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-dynamic-links:16.1.5'
implementation 'com.google.firebase:firebase-messaging:17.3.4'

implementation 'com.google.code.gson:gson:2.8.4'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'


implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

implementation 'com.github.bumptech.glide:glide:3.7.0'
annotationProcessor 'com.github.bumptech.glide:glide:3.7.0'

implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'com.github.hotchemi:android-rate:1.0.1'
implementation 'com.romandanylyk:pageindicatorview:1.0.2'
implementation 'com.karumi:dexter:5.0.0'
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.12.0'

implementation group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: '3.10.0'

}

Proguard内容

-keep class com.** { *; }
-dontwarn com.**
-dontwarn retrofit2.**
#-dontwarn okhttp3.**
-dontwarn okio.**


-keepattributes Signature
-keepattributes Annotation
-keep class okhttp3.* { *; }
-keep interface okhttp3.* { *; }
-dontwarn okhttp3.

-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn com.squareup.okhttp3.**
-keep class com.squareup.okhttp3.** { *; }
-keep interface com.squareup.okhttp3.* { *; }
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault
-dontwarn org.**

1 个答案:

答案 0 :(得分:1)

-dontwarn域中使用org.**是awfu,它会忽略应避免使用的大量错误!

您只需添加一些库向我们推荐的proguard规则。

但是此错误表示obfuscation中的某些类已更改,您应该查找哪些类具有此条件。然后只需添加以下规则即可保留这些内容:

-keep class packagename.* { *; }