Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JDK 12 with Android project

I am running Android Studio 3.5 Beta 5. I have been following a rabbit hole starting with trying to run unit tests with Robolectric against Android SDK 29. I saw an error that required running with Java 9. When I went to install JDK 9, it directed me to 10, then 11, then 12!

I downloaded JDK 12 and now I would like to configure Android Studio's JDK location to be 12. However, when I attempt to do that, I get the following warning message: "Please choose a valid JDK 8 directory". See screenshots below.

Is there another setting I have to change to get this dialog to allow me to choose a JDK greater than 8? Or is it just not possible?

project structure dialog

warning message

like image 330
B W Avatar asked Jul 11 '19 22:07

B W


People also ask

What version of JDK do I need for Android Studio?

Set the JDK version A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects. To use the bundled JDK, do the following: Open your project in Android Studio and select File > Project Structure in the menu bar.

How do I install the Android 12 SDK?

For the best development experience with the Android 12 SDK, use Android Studio Arctic Fox | 2020.3.1 or higher. Within Android Studio, you can install the Android 12 SDK as follows: Click Tools > SDK Manager. In the SDK Platforms tab, select Android 12. In the SDK Tools tab, select Android SDK Build-Tools 31. Click OK to install the SDK.

How do I use the bundled JDK in Android Studio?

To use the bundled JDK, do the following: 1 Open your project in Android Studio and select File > Project Structure in the menu bar. 2 In the SDK Location page and under JDK location, check the Use embedded JDK checkbox. 3 Click OK.

Is it possible to compile Android apps with higher JDK version?

3 you actually can compile Android apps using a higher JDK version while targeting Java 8 within your apps. it seems that this was supported in Android Studio versions before 3.5 beta 3, and according to the issue tracker, they plan on fixing this.


1 Answers

Oracle Java and Android Java aren't the same - they don't even use the same virtual machine.

So Sadly u can not use it now, until Android support it.

like image 167
Eslam Ahmad Avatar answered Sep 29 '22 13:09

Eslam Ahmad