Gradle构build失败

我的项目编译和执行良好的debugging模式,但是当我尝试生成签名的apk,出现错误。 这出现在消息日志上:

:app:proguardRelease Warning:android.support.v4.app.DialogFragment: can't find referenced class android.support.v4.app.DialogFragment$DialogStyle Warning:android.support.v4.app.FragmentTransaction: can't find referenced class android.support.v4.app.FragmentTransaction$Transit Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$ResolvedLayoutDirectionMode Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$LayoutDirectionMode Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$LayerType Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$AccessibilityLiveRegion Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$ImportantForAccessibility Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$OverScroll Warning:android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$EdgeGravity Warning:android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$LockMode Warning:android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$State Warning:there were 11 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) Exception while processing task java.io.IOException: Please correct the above warnings first. at proguard.Initializer.execute(Initializer.java:473) at proguard.ProGuard.initialize(ProGuard.java:233) at proguard.ProGuard.execute(ProGuard.java:98) at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074) at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139) at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115) at com.android.builder.tasks.Job.runTask(Job.java:48) at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41) at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227) at java.lang.Thread.run(Thread.java:745) :app:dexRelease UP-TO-DATE :app:crashlyticsStoreDeobsRelease :app:crashlyticsUploadDeobsRelease :app:validateExternalOverrideSigning :app:packageRelease FAILED Error:Execution failed for task ':app:packageRelease'. > Unable to compute hash of /home/kombo/RAL/Mpasho/app/build/intermediates/classes-proguard/release/classes.jar 

我已经尝试了所有可能的方式来通过更新我的构build工具,使用最新的gradle版本,检查所有的依赖关系和错误仍然显示补救。

我很确定v4支持库存在于项目中,因为在debugging模式下没有错误。

Solutions Collecting From Web of "Gradle构build失败"

升级所有与23(Android库,SDK等)相关的东西时,我也遇到了这个问题。

这个proguardconfiguration为我解决了这个问题:

 -dontwarn org.apache.http.** -dontwarn android.net.http.AndroidHttpClient -dontwarn com.google.android.gms.** -dontwarn com.android.volley.toolbox.** 

资源

原来,我省略了proguard文件中的getDefaultProguardFile('proguard-android.txt')行,并且正在使用proguard-rules.pro

在progaurd中添加了这两行

 -dontwarn android.net.http.AndroidHttpClient -dontwarn com.google.android.gms.** 

它的工作..

它与项目中使用的库有关。

默认的ProGuard文件已经有一个规则来忽略支持库警告。 如果你没有它,你可以添加到你的文件

 -dontwarn android.support.** 

但是最好添加一个默认的。 请参阅Android开发人员的Proguardconfiguration

这也可能是由于与包含.jar文件有关的错误/警告检查构build输出的proguard警告/错误。

我有与opencsv jar文件相关的问题。 Lakedaemon在上述评论中的暗示帮助我解决了它。

我认为你的应用程序build.gradle的buildTypes > release > minifyEnabled is true

这导致你得到这个错误消息。

避免这个错误消息,设置buildTypes > release > minifyEnabled is false


  buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } 

试着查看整个错误信息。 它可能包含两次包含库的信息。 这是我的情况的问题,并删除重复包括后,它是固定的。