Android studio 构建 apk 时出现 transformClassesAndResourcesWithProguardForRelease 错误

标签 android gradle android-proguard

当我尝试使用发布构建变体构建我的项目时,我收到一个错误:

Information:Gradle tasks [:app:assembleRelease]
:app:preBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:checkReleaseManifest
:app:preDebugBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareComBalysvMaterialRipple101Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidAnswers138Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidBeta116Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlytics257Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlyticsCore2310Library UP-TO-DATE
:app:prepareComGithubKsoichiroAndroidpagecontrol011Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase830Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement830Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMaps830Library UP-TO-DATE
:app:prepareComPkmmteViewCircularimageview11Library UP-TO-DATE
:app:prepareIoFabricSdkAndroidFabric1312Library UP-TO-DATE
:app:prepareItNeokreeMaterialNavigationDrawer133Library UP-TO-DATE
:app:prepareReleaseDependencies
:app:compileReleaseAidl UP-TO-DATE
:app:compileReleaseRenderscript UP-TO-DATE
:app:generateReleaseBuildConfig UP-TO-DATE
:app:mergeReleaseShaders UP-TO-DATE
:app:compileReleaseShaders UP-TO-DATE
:app:generateReleaseAssets UP-TO-DATE
:app:mergeReleaseAssets UP-TO-DATE
:app:processReleaseManifest UP-TO-DATE
:app:fabricGenerateResourcesRelease
:app:generateReleaseResValues UP-TO-DATE
:app:generateReleaseResources
:app:mergeReleaseResources
:app:processReleaseResources
:app:generateReleaseSources
:app:incrementalReleaseJavaCompilationSafeguard UP-TO-DATE
:app:compileReleaseJavaWithJavac UP-TO-DATE
:app:compileReleaseNdk UP-TO-DATE
:app:compileReleaseSources UP-TO-DATE
:app:processReleaseJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
:app:transformClassesAndResourcesWithProguardForRelease
ProGuard, version 5.2.1
Reading input...
Reading program jar [/Users/zsolt/.gradle/caches/modules-2/files-2.1/io.realm/realm-android/0.84.2/61e6edd15626bc5278a00593b604274539222a8f/realm-android-0.84.2.jar] (filtered)
Reading program jar [/Users/zsolt/.gradle/caches/modules-2/files-2.1/com.squareup.retrofit/converter-gson/2.0.0-beta2/392c3d09e0f5e7087544093cc0cb23bb9c7af5fa/converter-gson-2.0.0-beta2.jar] (filtered)
Reading program jar [/Users/zsolt/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-runtime/0.11.91.1/8669cc696e56855d38f0ca876586a9324dad5adc/kotlin-runtime-0.11.91.1.jar] (filtered)
Reading program jar [/Users/zsolt/.gradle/caches/modules-2/files-2.1/com.squareup.okio/okio/1.6.0/98476622f10715998eacf9240d6b479f12c66143/okio-1.6.0.jar] (filtered)
Note: the configuration keeps the entry point 'android.support.v7.widget.SearchView { void setSuggestionsAdapter(android.support.v4.widget.CursorAdapter); }', but not the descriptor class 'android.support.v4.widget.CursorAdapter'
Note: the configuration keeps the entry point 'android.support.v7.widget.SearchView$SearchAutoComplete { void setSearchView(android.support.v7.widget.SearchView); }', but not the descriptor class 'android.support.v7.widget.SearchView'
Note: the configuration keeps the entry point 'android.support.v7.widget.Toolbar { void setOnMenuItemClickListener(android.support.v7.widget.Toolbar$OnMenuItemClickListener); }', but not the descriptor class 'android.support.v7.widget.Toolbar$OnMenuItemClickListener'
Note: the configuration keeps the entry point 'android.support.v7.widget.ViewStubCompat { void setOnInflateListener(android.support.v7.widget.ViewStubCompat$OnInflateListener); }', but not the descriptor class 'android.support.v7.widget.ViewStubCompat$OnInflateListener'
Note: the configuration keeps the entry point 'com.google.android.gms.ads.identifier.AdvertisingIdClient { com.google.android.gms.internal.zzav zza(android.content.Context,com.google.android.gms.common.zza); }', but not the descriptor class 'com.google.android.gms.common.zza'
Note: the configuration keeps the entry point 'com.google.android.gms.common.GooglePlayServicesUtil { android.app.Dialog zza(int,android.app.Activity,android.support.v4.app.Fragment,int,android.content.DialogInterface$OnCancelListener); }', but not the descriptor class 'android.support.v4.app.Fragment'
Note: the configuration keeps the entry point 'com.google.android.gms.common.GooglePlayServicesUtil { boolean showErrorDialogFragment(int,android.app.Activity,android.support.v4.app.Fragment,int,android.content.DialogInterface$OnCancelListener); }', but not the descriptor class 'android.support.v4.app.Fragment'
Note: the configuration keeps the entry point 'io.realm.internal.CheckedRow { void nativeSetMixed(long,long,io.realm.internal.Mixed); }', but not the descriptor class 'io.realm.internal.Mixed'
Note: the configuration keeps the entry point 'io.realm.internal.Table { void nativeUpdateFromSpec(long,io.realm.internal.TableSpec); }', but not the descriptor class 'io.realm.internal.TableSpec'
Note: the configuration keeps the entry point 'io.realm.internal.Table { void nativeSetMixed(long,long,long,io.realm.internal.Mixed); }', but not the descriptor class 'io.realm.internal.Mixed'
Note: the configuration keeps the entry point 'io.realm.internal.TableView { void nativeSetMixed(long,long,long,io.realm.internal.Mixed); }', but not the descriptor class 'io.realm.internal.Mixed'
Note: the configuration keeps the entry point 'io.realm.internal.UncheckedRow { void nativeSetMixed(long,long,io.realm.internal.Mixed); }', but not the descriptor class 'io.realm.internal.Mixed'
Note: there were 2 references to unknown classes.
      You should check your configuration for typos.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: there were 36 classes trying to access generic signatures using reflection.
      You should consider keeping the signature attributes
      (using '-keepattributes Signature').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 5 classes trying to access enclosing classes using reflection.
      You should consider keeping the inner classes attributes
      (using '-keepattributes InnerClasses').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 2 classes trying to access enclosing methods using reflection.
      You should consider keeping the enclosing method attributes
      (using '-keepattributes InnerClasses,EnclosingMethod').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 33 unkept descriptor classes in kept class members.
      You should consider explicitly keeping the mentioned classes
      (using '-keep').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#descriptorclass)
Note: there were 11 unresolved dynamic references to classes or interfaces.
      You should check if you need to specify additional program jars.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Note: there were 2 class casts of dynamically created class instances.
      You might consider explicitly keeping the mentioned classes and/or
      their implementations (using '-keep').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclasscast)
Note: there were 7 accesses to class members by means of introspection.
      You should consider explicitly keeping the mentioned class members
      (using '-keep' or '-keepclassmembers').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclassmember)
Warning:there were 1798 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning:there were 1 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Warning:there were 1 unresolved references to library class members.
         You probably need to update the library versions.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
:app:transformClassesAndResourcesWithProguardForRelease FAILED
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
Information:BUILD FAILED
Information:Total time: 2.957 secs
Information:1 error
Information:786 warnings
Information:See complete output in console

此列表只是完整日志的一部分。我已经尝试了 -dontwarn 解决方案,但它没有用。之后,我尝试-keep 所有库,但没有成功。这是我在项目中使用的库的列表:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.squareup.okhttp:logging-interceptor:2.6.0'
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.pkmmte.view:circularimageview:1.1'
    compile 'it.neokree:MaterialNavigationDrawer:1.3.3'
    compile 'com.github.ksoichiro:androidpagecontrol:0.1.1'
    compile 'io.realm:realm-android:0.84.2'
    compile 'com.google.android.gms:play-services-maps:8.3.0'
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.google.guava:guava:18.0'
    compile 'joda-time:joda-time:2.9.1'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
        transitive = true;
    }
}

最佳答案

这是因为proguard。查找您使用的库并检查它们是否在其实现中提到了“Proguard”部分,并将该部分代码复制到发布版本中使用的混淆文件中。例如 Retrofit 在 http://square.github.io/retrofit/ 的底部有 4 行

关于Android studio 构建 apk 时出现 transformClassesAndResourcesWithProguardForRelease 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38254949/

相关文章:

java - maven项目依赖于eclipse中的gradle一

android - Android Studio 的配置文件

ProGuard 正在删除一些必需的代码?

java - Retrofit2 proguard 发生 : java. lang.AbstractMethodError:抽象方法 "void retrofit2.Callback.onResponse(retrofit2.Call, retrofit2.Response)"

java - 使用在 source/build/target/product/security/中找到的 key 将 apk 签名为系统

android - Android webview 和浏览器上的地理定位失败

java - SpringMVC 应用程序的 Swagger API 数组为空

android - 任务 ':app:kaptDebugKotlin' 执行失败。 > 执行 org.jetbrains.kotlin.gradle.internal.KaptExecution 时发生故障

android - 布局资源文件中的两个线性布局,但只有一个显示

android - Retrofit2 proguard 删除参数