Java 错误:任务 ':app:packageRelease' 的执行失败。> 无法计算 /../AndroidStudioProjects/../classes.jar 的哈希值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31643339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error:Execution failed for task ':app:packageRelease'. > Unable to compute hash of /../AndroidStudioProjects/../classes.jar
提问by Jamaal
I'm trying to do a 'release' build on an Android app and I keep on getting this error of:
我正在尝试在 Android 应用程序上进行“发布”构建,但不断收到以下错误:
Unable to compute hash of /../AndroidStudioProjects/../classes.jar
无法计算 /../AndroidStudioProjects/../classes.jar 的哈希值
And then when I look into that directory for 'classes.jar' the file isn't there. Do I have to create this file myself with a gradle task?
然后当我查看该目录中的“classes.jar”时,该文件不存在。我必须自己用 gradle 任务创建这个文件吗?
There's something going on with proguard here but it's not giving much useful information other than 'Unable to compute hash...."
proguard 这里发生了一些事情,但除了“无法计算哈希......”之外,它没有提供太多有用的信息。
Here's my gradle.build file:
这是我的 gradle.build 文件:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
buildConfigField "String", "SERVER_URL", '"http://10.0.2.2:3000"'
}
release {
buildConfigField "String", "SERVER_URL", '"https://example.com"'
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debugRelease {
buildConfigField "String", "SERVER_URL", '"https://example.com"'
debuggable true
jniDebuggable false
renderscriptDebuggable false
minifyEnabled false
zipAlignEnabled true
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:cardview-v7:22.1.1'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
}
If someone could help me debug this issue that'd be great.
如果有人能帮我调试这个问题,那就太好了。
采纳答案by Jamaal
I figured out the problem:
我解决了这个问题:
Open up the proguard-rules.pro
for your project and add this to the bottom:
打开proguard-rules.pro
您的项目并将其添加到底部:
-dontwarn java.nio.file.Files
-dontwarn java.nio.file.Path
-dontwarn java.nio.file.OpenOption
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Basically how I solved it was this I tried to run my app in 'release' mode and got a bunch of errors similar to this guy here: https://github.com/square/okio/issues/144
基本上我是如何解决这个问题的,我试图在“发布”模式下运行我的应用程序,但遇到了一堆类似于这里的人的错误:https: //github.com/square/okio/issues/144
I pretty much followed what he said and fixed it.
我几乎按照他说的去做并修复了它。
Hope this can help others with generating their APK's!
希望这可以帮助其他人生成他们的 APK!
回答by WindsurferOak
I know there's already an answer here, but my situation was a little different, and I wanted to share it.
我知道这里已经有了答案,但我的情况有点不同,我想分享一下。
For me, my project's proguard file, namely, proguard-rules.pro
, was somehow renamed to proguard-android.txt
.
对我来说,我的项目的 proguard 文件,即 ,proguard-rules.pro
以某种方式被重命名为proguard-android.txt
.
The proguard-android.txt
is reserved for Android's default proguard rules, so essentially, I was overriding Android's proguard file, which was causing havoc, and I would get the Unable to compute hash message.
这proguard-android.txt
是为 Android 的默认 proguard 规则保留的,所以基本上,我覆盖了 Android 的 proguard 文件,这造成了严重破坏,我会得到Unable to compute hash message。
Once I changed the filename in my project from proguard-android.txt
to proguard-rules.pro
I was able to get things working.
一旦我将项目中的文件名从 更改为proguard-android.txt
,proguard-rules.pro
我就可以开始工作了。
回答by goRGon
For me the following 2 lines inside proguard.cfghelped:
对我来说,proguard.cfg 中的以下两行有帮助:
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
回答by mavixce
I know this is an old question but maybe this answer works for someone. I added -dontwarn butterknife.**
to proguard then gradle builds properly.
我知道这是一个老问题,但也许这个答案对某人有用。我添加 -dontwarn butterknife.**
到 proguard 然后 gradle 正确构建。
回答by georgiecasey
All the current answers to this question are just giving the Proguard rules that worked for them, every fix will be different. First off, confirm it's a Proguard problem by checking that the classes-proguard directory is somewhere in the error message, something like this: Unable to compute hash of /Users/Documents/projectX/app/build/intermediates/classes-proguard/release/classes.jar
这个问题的所有当前答案只是给出了适用于他们的 Proguard 规则,每次修复都会有所不同。首先,通过检查 classes-proguard 目录是否在错误消息中的某个位置来确认这是一个 Proguard 问题,如下所示:Unable to compute hash of /Users/Documents/projectX/app/build/intermediates/classes-proguard/release/classes.jar
This means it's caused by an earlier Proguard error so you need to scroll up in the Messages window or Gradle Console window and check what warnings or errors you're getting. Just as an example, in my current project, Square's Picasso library is causing the error:
Warning: com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
. I just added -dontwarn com.squareup.okhttp.**
to ignore the warnings, and the app still worked as normal.
这意味着它是由早期的 Proguard 错误引起的,因此您需要在 Messages 窗口或 Gradle Console 窗口中向上滚动并检查您收到哪些警告或错误。举个例子,在我当前的项目中,Square 的 Picasso 库导致了错误:
Warning: com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
. 我只是添加-dontwarn com.squareup.okhttp.**
忽略警告,应用程序仍然正常工作。
A lot of the Proguard errors will be warnings about some class so just adding -dontwarn for whatever class is causing it in your project often works.
许多 Proguard 错误都是关于某个类的警告,因此只需为项目中导致它的任何类添加 -dontwarn 就可以了。
I know the StackOverflow way is just Google the error message, copy and paste the top answer and hope for the best but here you've to understand it a bit and figure out the proguard rules for you!
我知道 StackOverflow 的方式只是谷歌的错误信息,复制并粘贴最重要的答案,并希望得到最好的结果,但在这里你必须稍微了解它并为你找出 proguard 规则!
回答by Nigus Girma
Just create a file proguard-rules.pro and add "-dontwarn package names" that gave you warning on the message.
只需创建一个文件 proguard-rules.pro 并添加“-dontwarn package names”,在消息中向您发出警告。
回答by user1837311
Disabling the minifyEnabledoption from my gradle file corrected the error in my build.
从我的 gradle 文件中禁用minifyEnabled选项更正了我的构建中的错误。
build.gradle
构建.gradle
buildTypes {
release {
// DISABLE OPTION
//minifyEnabled true
proguardFiles 'proguard.cfg'
}
}