【问题标题】:Android studio build apk with transformClassesAndResourcesWithProguardForRelease errorAndroid Studio 构建带有 transformClassesAndResourcesWithProguardForRelease 错误的 apk
【发布时间】:2016-07-07 20:44:41
【问题描述】:

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

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;
    }
}

【问题讨论】:

    标签: android gradle android-proguard


    【解决方案1】:

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

    【讨论】:

    • 理想情况下,您应该在添加每个库后在发布模式下测试您的应用程序,以确保它可以正常工作,因为它可以为您节省大量时间。现在收集所有 proguard 的东西可能需要一段时间
    • 是的,确实如此。可悲的是,我没有意识到这一点(我应该告诉我我只是一个初级开发人员吗?:D)。
    • 每个开发者都必须经历它:)
    • 一个插件将非常非常非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 2016-12-24
    • 2017-03-22
    • 2022-10-25
    • 2016-03-03
    相关资源
    最近更新 更多