错误:Gradle:任务 ':app:preDexDebug' 执行失败 [英] Error: Gradle: execution failed for task ':app:preDexDebug'

查看:30
本文介绍了错误:Gradle:任务 ':app:preDexDebug' 执行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从另一个项目中创建了一个自己创建的 jar,作为库导入到我的另一个项目中.当我更改该项目中的代码并导出一个新 jar 以替换旧的 jar 时,我无法再运行我的应用程序.我只收到以下错误:

I had a self created jar from another projected imported as a library into my other project. When I changed code in that project and exported a new jar to replaced the old one I cannot run my app anymore. 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.

推荐答案

过去,当我们的项目编译时使用的 Java 版本与用于编译图书馆.魔数只是用于识别类文件,所以这不是问题.问题在于 Java 版本 (0034.0000 == Java 8).

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. 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 6,这可能需要从您的代码中删除较新的语法.在我们的例子中,项目和库都是我们的,所以我们能够添加以下内容来强制我们需要的 Java 版本:

The easiest thing to do is target Java 6, which may require removing newer syntax from your code. 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:

对于 android 库,将此代码添加到android"扩展对象:

for android libraries, add this code to the "android" extension object:

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

Java 库

对于 Java 库,在顶级"添加此代码:

Java Libraries

for java libraries, add this code at the "top level":

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

注意:最后两行是唯一重要的,我添加了其他行只是为了显示这些行所属的位置,相对于您的 gradle 构建文件的其余部分.

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:任务 ':app:preDexDebug' 执行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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