简体   繁体   English

错误:Gradle:任务执行失败':app:preDexDebug'

[英]Error: Gradle: execution failed for task ':app:preDexDebug'

I had a self created jar from another projected imported as a library into my other project. 我有一个自己创建的jar从另一个作为库导入到我的另一个项目中。 When I changed code in that project and exported a new jar to replaced the old one I cannot run my app anymore. 当我更改该项目中的代码并导出一个新的jar来替换旧的时,我再也无法运行我的应用了。 I only get the following error: 我只收到以下错误:

在此输入图像描述

I have tried removing and adding and adding as dependency, adding as library. 我尝试删除,添加和添加为依赖项,添加为库。 Nothing seems to work. 似乎没什么用。 I have also done clean build and a rebuild. 我也做了干净的构建和重建。

We've seen this problem in the past when our project was compiling with a version of Java different from the one used to compile the library. 过去我们看到过这个问题,当时我们的项目是用不同于编译库的Java版本编译的。 The magic number is just used to identify class files so that is not the problem here. 神奇的数字仅用于识别类文件,因此这不是问题。 The issue is the java version (0034.0000 == Java 8). 问题是java版本(0034.0000 == Java 8)。

The easiest thing to do is target Java 6, which may require removing newer syntax from your code. 最简单的方法是针对Java 6,这可能需要从代码中删除更新的语法。 In our case, both the project and library were ours so we were able to add the following to force the version of Java that we needed: 在我们的例子中,项目和库都是我们的,所以我们能够添加以下内容来强制我们需要的Java版本:

Android Libraries Android库

for android libraries, add this code to the "android" extension object: 对于android库,将此代码添加到“android”扩展对象:

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
    ...
}

Java Libraries Java库

for java libraries, add this code at the "top level": 对于java库,在“顶级”添加此代码:

apply plugin: 'java'

version '1.8.1'
group   'com.yourcompany.package'

sourceCompatibility = JavaVersion.VERSION_1_6   //these two lines
targetCompatibility = JavaVersion.VERSION_1_6   //are the only ones that matter

NOTE: the last two lines are the only ones that matter, I added the others just to show where those lines belong, in respect to the rest of your gradle build file. 注意:最后两行是唯一重要的,我添加其他行只是为了显示这些行所属的位置,相对于gradle构建文件的其余部分。

For us, this was caused by the Android SDK build-tools version. 对我们来说,这是由Android SDK构建工具版本引起的。 Got the problem on v23.x, but not v22.x. 在v23.x上遇到问题,但不是v22.x. You need to uninstall v23 for cordova to pick v22. 你需要卸载v23 for cordova来选择v22。

Possibly a symptom rather than a cause, but this may unstick someone in the same situation. 可能是一种症状而不是一种原因,但这可能会使某些人处于相同的情况。

Although your problem seems fixed, I ended up here with a similar error (while building the samples from developer.android.com). 虽然您的问题似乎已得到修复,但最终我遇到了类似的错误(同时从developer.android.com构建示例)。 In case it's helpful to others, I was able to solve it by setting JAVA_HOME to the appropriate value. 如果它对其他人有帮助,我可以通过将JAVA_HOME设置为适当的值来解决它。 In my case it was: 在我的情况下它是:

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64

adding: 添加:

sourceCompatibility = JavaVersion.VERSION_X_X
targetCompatibility = JavaVersion.VERSION_X_X

in the Android project gradle file and the Java library gradle file worked for me. 在Android项目gradle文件和Java库gradle文件为我工作。

Sorry I would have +1'd it but don't have a high enough reputation 对不起,我会给它+1,但没有足够高的声誉

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 生成错误,Gradle->错误:任务':app:preDexDebug'的执行失败。 > org.gradle.process.internal.ExecException: - Build error ,Gradle -> Error:Execution failed for task ':app:preDexDebug'. > org.gradle.process.internal.ExecException: 任务':app:preDexDebug的执行失败 - Execution failed for task ':app:preDexDebug 模块依赖性导致错误:Gradle:Android Studio中任务':app:preDexDebug'的执行失败 - Module dependency leads to Error:Gradle: Execution failed for task ':app:preDexDebug' in Android Studio 编译时出错-执行失败于':app:preDexDebug' - ERROR at compiling - execution failed at ':app:preDexDebug' Android Studio无法运行项目-错误:任务':app:preDexDebug'的执行失败。 - Android Studio cannot run project - Error:Execution failed for task ':app:preDexDebug'. 错误:任务':app:preDexDebug'的执行失败。 >…以非零值1结束 - Error:Execution failed for task ':app:preDexDebug'. > … finished with non-zero value 1 任务':app:preDexDebug'的执行失败添加球衣依赖关系导致生成错误 - Execution failed for task ':app:preDexDebug' Adding jersey dependencies give build error Gradle错误:任务':app:dexDebug'的执行失败。 - Gradle Error:Execution failed for task ':app:dexDebug'. 错误:任务':app:transformClassesWithDexForDebug'Gradle的执行失败 - Error:Execution failed for task ':app:transformClassesWithDexForDebug' Gradle Gradle错误:任务':app:transformClassesWithJarMergingForDebug'的执行失败 - Gradle Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM