当minifyEnabled为true时,构建APK时出错

编程入门 行业动态 更新时间:2024-10-25 00:25:54
本文介绍了当minifyEnabled为true时,构建APK时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要启用proguard,因此我将minifyEnabled设置为true.但是,当我尝试构建发行版APK时,出现以下错误:

I need to enable proguard, so I set minifyEnabled to true. However, I then get the following error when trying to build a release APK:

错误:任务':app:packageRelease'的执行失败. 无法计算.../app/build/intermediates/classes-proguard/release/classes.jar

Error:Execution failed for task ':app:packageRelease'. Unable to compute hash of .../app/build/intermediates/classes-proguard/release/classes.jar

听起来我需要根据所使用的库更新我的proguard-rules.这是我的依赖项:

Sounds like I need to update my proguard-rules according to the libraries I'm using. Here are my dependencies:

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.jakewharton:butterknife:7.0.1' compile 'com.parse.bolts:bolts-android:1.+' compile 'com.parse:parse-android:1.+' compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') { transitive = true; } compile('com.mopub.sdk.android:mopub:4.0.0@aar') { transitive = true; } }

找出每种方法的保护规则的最佳方法是什么?到目前为止,我只发现了ButterKnife's

What's the best way to find out what to put in proguard-rules for each of these? So far I've only found ButterKnife's

推荐答案

-dontwarn 在所有内容上都可能引起另一个问题,如果在不引发错误的情况下剥离了必需的依赖项.

-dontwarn on everything might cause another problem if required dependencies get stripped out without throwing an error.

您最好的选择是通过检查日志输出(或将日志发布在此处以便某人查看),然后使用 -keep 对其进行配置,以找到阻止构建发生的库 -dontwarn 根据需要,在 proguard-rules.pro 文件中.

Your best bet is to find the libraries that are preventing the build from occurring by checking your log output (or posting it here so someone can take a look) and then configuring them with -keep or -dontwarn as required, in the proguard-rules.pro file.

在大多数情况下,人们以前都是针对您所使用的相同库执行此操作的,而您只需要查找示例规则文件并查看其配置即可了解其配置,像这样的OkHttp ,并且团队经常有这个在GitHub上的图书馆项目的设置部分中像这样的翻新版.

In most cases people have done this before for the same libraries that you're using, and you just need to find an example rules file and take a look at their config to learn how it's done, like this one for OkHttp, and teams often have this in the setup section of library projects on GitHub like this one for Retrofit.

更多推荐

当minifyEnabled为true时,构建APK时出错

本文发布于:2023-11-15 16:53:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:minifyEnabled   true   APK

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!