Reputation: 24005
I have a pure Java module in an Android project. My project compiles by default using JDK 8, but I want my Java module to compile using JDK 7. How do I specify for my pure java module a compile level of 1.7? Keep in mind that I am not wanting to override the project level compile level of 1.8.
Upvotes: 0
Views: 2355
Reputation: 390
You can do this in two ways:
1-Add this block to your app build.gradle
android{
....
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
2-Add this block with android studio:
Update:
Note: If you using kotlin as your Gradle language(kotlin dsl), you should do it this way:
android{
....
compileOptions {
setSourceCompatibility(JavaVersion.VERSION_1_8)
setTargetCompatibility(JavaVersion.VERSION_1_8)
}
}
Upvotes: 2
Reputation: 1428
Setting target/source compatibility levels of a java library module in Android Studio can be done adding this to the build.gradle of the java library module:
tasks.withType(JavaCompile) {
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
}
Upvotes: 0
Reputation: 1
Two ways
In gradle.properties
in your HOME_DIRECTORY set org.gradle.java.home=/path_to_jdk_directory
In your gradle.build
compileJava.options.fork = true
compileJava.options.forkOptions.executable = /path_to_javac
Upvotes: 0
Reputation: 3193
You can do the following into app/build.gradle
:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
Upvotes: -1
Reputation: 24005
I found the answer:
//noinspection GroovyUnusedAssignment
sourceCompatibility = 1.7
//noinspection GroovyUnusedAssignment
targetCompatibility = 1.7
You can specify the source and target compatibility levels. This is needed often when compiling a mix of Android and Java modules.
Upvotes: 2