Does Android Studio 3 support Java 9 for Android development? If so, what features of Java 9 are supported?

老子叫甜甜 提交于 2019-11-29 04:39:18

问题


I'm going to install Android Studio 3 in order to develop an Android application.

I'd like to know if it is possible to use Java 9 for Android development? If so, does it support all of the Java 9 features?


回答1:


As far as I know, the IDE itself supports Java 9. This means you can write a Java 9 desktop program, or run the IDE with JDK 9.

However, Android itself does not support Java 9 (yet). You can still download JDK 9, although I have seen some questions on problems related to Android Studio and Java 9. Personally, I have Java 9 and Android Studio runs without problems.

The Android SDK is the development kit you'll be dealing with, and with source compatibility you'll get language features similar to Java 6, 7, or 8, depending on your settings. So you can download JDK 9 and use that most likely without issues, but you can't use any of the language features in any Android apps.

As for differences between the JDK and the Android SDK, you should read this. Android currently supports a subset of Java 8 features, but not everything. It might never support everything, or leave out some parts of Java 8, even if it later supports some parts on Java 9 or higher.




回答2:


UPDATE: as of https://jakewharton.com/androids-java-8-support/, it seems like this should almost work by now (as well as for Java 9, 10, 11, and 12). Or just use Kotlin.

To help the last steps along, you can star the issue.


As of now, the Android SDK does not even support java 8 completely:

Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features that vary by platform version. This page describes the Java 8 language features you can use, how to properly configure your project to use them, and any known issues you may encounter. [emphases mine]

That probably needs to be supported completely before Java 9 is approached.




回答3:


Just tried to do it with Ubuntu 18.04 which uses Java 10 already. You run into tons of problems from invalid java certificates to extra warnings on gradle invocations etc. It's a mess and hopefully solved soon, you will find solutions to every problem via google but it's more easy to install Java 8 instead.

I have no idea about using the language itself inside Android application code, because i'm a full NDK C++ programmer and only use the toolchain which contains many java programs.



来源:https://stackoverflow.com/questions/47627499/does-android-studio-3-support-java-9-for-android-development-if-so-what-featur

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!