Use a JDK from another OpenJDK provider in Android Studio

About the JDK used to build Android Studio projects

Android Studio 2.2 and later includes a Java development environment called ** OpenJDK **. By default, your Android application project will be built by this OpenJDK. However, there is no special mechanism that allows builds to pass only with this OpenJDK. ** Oracle JDK **, of course ** AdoptOpenJDK **, ** Azul Zulu **, ** Amazon Corretto * It is also possible to use a JDK from another OpenJDK provider such as *.

Setting method

To use the JDK you installed for your build, do the following:

--Select Configure Project DefaultsProject Structure at the bottom right of the Start screen to bring up the settings screen. -Uncheck ʻUse embedded JDKand enter the location of the JDK in the text box below it. You can also select from the dialog with the…` button on the right.

If you download the zip file of Azul Zulu's OpenJDK 8u202 build (64bit version) and extract it under C: \ opt, it will be called C: \ opt \ zulu8.36.0.1-ca-jdk8.0.202-win_x64. The folder will be created. If you specify this folder by the above operation, it will be as shown in ** Figure 1 **.

Figure 1
Figure 1

Take advantage of junctions on Windows

With the settings shown in ** Figure 1 **, you have to change the settings every time the JDK is updated, but in Windows, the OS has a function called ** junction ** as standard. By utilizing it, you can change the version of JDK without manipulating the settings on the Android Studio side.

To create a junction to the folder extracted in the Azul Zulu example above, at the command prompt:

C:\opt>mklink /j jdk8 C:\opt\zulu8.36.0.1-ca-jdk8.0.202-win_x64

The junction C: \ opt \ jdk8 will now point to the same location as C: \ opt \ zulu8.36.0.1-ca-jdk8.0.202-win_x64. After this, by setting C: \ opt \ jdk8 as the JDK location of Android Studio, it can be operated in the same way as the previous setting example.

Replacing the junction

After updating the JDK, just replace the junction. It cannot be overwritten, so delete it with the rmdir command (you can delete it with Explorer) and then create a new junction.

C:\opt>rmdir jdk8
C:\opt>mklink /j jdk8 <Path to the new JDK>

This completes the replacement.

Is it possible to use JDK 11?

If you set the path to JDK 11 in the same way and create a new project, you will get an error as shown in ** Figure 2 **.

Figure 2
Figure 2

This can be avoided by opening the settings screen with Configure Settings at the bottom right of the Start screen, selecting ʻExperimental from the tree in the left pane, and unchecking ʻOnly sync the active variant. (** Figure 3 **). However, it seems necessary to keep in mind that it is experimental.

Figure 3
Figure 3

Recommended Posts

Use a JDK from another OpenJDK provider in Android Studio
Use the JDK used in Android Studio in the terminal
How to use ExpandableListView in Android Studio
Notes in Android studio
I got a cannot resolve symbol in Android Studio
I tried to create a simple map app in Android Studio
Determining if a custom keyboard is enabled in Android Studio (Java)
Automatically insert `@SuppressWarnings` in Android Studio
OkHttp3 (GET, POST) in Android Studio
Reintroducing Java 8 available from Android Studio 2.4
[Talend] Switching from Oracle JDK to OpenJDK
Features in Oracle JDK 8 but not in OpenJDK
Java to C and C to Java in Android Studio
I have a question about Android studio.