Reputation: 3615
In the latest release of Android Studio (0.4.2), a new setting has been added when creating a new project, namely Language Level I want to know what that refers to, and the consequence of selecting any of the provided options. The doc doesn't give me a clear picture of this and i don't want to select an option when i don't know what that will result in? Thanks
Upvotes: 3
Views: 6493
Reputation: 7938
Java 7 support was added at build tools 19. You can use now features like the diamond operator, multi-catch, try-with-resources, strings in switches, etc. Add the folowing 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.
Upvotes: 0
Reputation: 3273
The answer can be phrased better, IMHO. The docs are clear about Java 7 and below.
Upvotes: 1
Reputation: 63955
It's about what Java language level you want to use. KitKat supports full Java 7, Gingerbread and up support Java 6 and older versions are Java 5. At least when it comes to the core Java APIs. Roughly the same setting is mentioned here.
You can often use language features that were added in one version in an older version if the compiler knows how to do it. For example the Diamond Operator was added in Java 7 but you can still use that feature in Java 6 since
List<String> list = new ArrayList<>();
actually compiles into the same thing as
List<String> list = new ArrayList<String>();
did.
The "try with resource" construct on the other hand can't be compiled into legal Java 6 compatible code and is therefore exclusive to Apps that require KitKat and up.
Upvotes: 3