Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

java - 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. 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:

enter image description here

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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 Libraries

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

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...