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 *.
To use the JDK you installed for your build, do the following:
--Select Configure
→ Project Defaults
→ Project 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 |
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.
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.
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 |
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 |
Recommended Posts