Saturday, 4 February 2017
java - How to set -source 1.7 in Android Studio and Gradle
Answer
Answer
I'm getting following error when trying to compile my project in Android Studio:
Gradle: error: diamond operator is not supported in -source 1.6
I have 1.7 set as target in all project preferences I've found. Also the path displayed in project SDK's under 1.7 SDK is correct path to java 1.7 installation.
Even when I run java -version in terminal, it tells me I'm running on java 1.7.
I have tried to set JAVA_HOME env variable to this:
/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home
The error does not go away. How do I eliminate the error?
Answer
Java 7 support was added at build tools 19. You can now use features like the diamond operator, multi-catch, try-with-resources, strings in switches, etc. Add the following to your build.gradle
.
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
Gradle 1.7+, Android gradle plugin 0.6.+ are required.
Note, that only try with resources require minSdkVersion
19. Other features works on previous platforms.
Link to android gradle plugin user guide
Link to see how source vs target are different
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
A fair amount of the second act of The Dark Knight Rises has a class warfare plotline. This is foreshadowed in the trailers with Selina Ky...
-
I want to create an options array from a string. How can i create an array as { width : 100, height : 200 } from a string ...
-
I'm trying to set the size of a CardView inside of a DialogFragment , but I get this error: java.lang.NullPointerException: Attempt t...
No comments:
Post a Comment