I tried to add a module to an Android project and make the main module dependent on it and I got this error:
Error:Gradle: Execution failed for task ':app:preDexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 1
I have a project with the main module app and added a module mylib and app depends on mylib.
Android Studio 1.2.2.
settings.gradle:
include ':app', ':mylib'
build.gradle from app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
compileOptions {
sourceCompatibility org.gradle.api.JavaVersion.VERSION_1_8
targetCompatibility org.gradle.api.JavaVersion.VERSION_1_8
}
...
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':mylib')
}
build.gradle from mylib:
apply plugin: 'java'
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
targetCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
The JAVA_HOME variable:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
The problem starts when I add line compile project(':mylib') to build.gradle, sometimes when I rebuild the project, but always when I try to run it. The VERSION_1_8 statements don't solve the problem.
What can be wrong? Any help will be very much appreciated.
I have the same problem and I found the solution from this pure java unit tests tutorial, it said Android currently support is Java 1.7.
Adding pure Java unit tests to an Android project
In short, just set your java lib module to 1.7, so your build.gradle in mylib may like this.
apply plugin: 'java'
dependencies {
sourceCompatibility = 1.7
targetCompatibility = 1.7
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Hope this can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With