当 minifyEnabled 为 true 时构建 APK 时出错 [英] Error building APK when minifyEnabled true

查看:97
本文介绍了当 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 规则.这是我的依赖项:

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

找出在 proguard-rules 中为每一个添加什么的最佳方法是什么?到目前为止,我只找到了 ButterKnife 的

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 上库项目的设置部分 就像这个用于 Retrofit.

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 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆