I stumbled on the Java version in Android Studio, so I will summarize it

Introduction

Since I started doing practical internships for the past few months, I have been building an environment every time the internship destination changes, but due to doing it properly, I have repeatedly stumbled on errors caused by the JDK version. I did.

Check every time

Oh ... is it due to the JDK version? So what are you going to do? Since it is barren to check, I wrote an article as a memorandum.

This article is a workaround for your use case and may not apply to others, but I'd love to update it from time to time.

A concrete use case that stumbled

First,

java -vesion

You can check some versions of your own JDK by hitting in the terminal, so for your reference.

How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

My JDK at this time

java 12.0.2 2019-07-16

was.

Some modules have been deprecated from the standard library when the "modules" feature was added in Java 9.

External JAR required to use JAXB in Java 9 and above # 49

With the addition of this function, the module JAXB has also been deprecated, and it seems that the above error has occurred. It will not be reproduced in Java 8 or lower, but will be reproduced in Java 9 or higher environment.

solution

For Java 9 and 10, run-time options

--add-modules java.xml.bind

If you specify, you can surpass it once.

It's a hassle to add options every time, or if you have a JDK environment above Java 10 in the first place, try the ** brute force solution ** below.

Forcible solution

Use the Android Studio JDK

First thing you need to know

** Android Studio provides the Java execution environment itself. ** **

Therefore, as mentioned in the article Java Path memo that Android Studio uses when creating apk, we usually use Android with GUI. When running in Studio, the application module is built and the apk is created in ** Android Studio Java environment **.

vice versa,

Terrminal at the bottom of Android Studio and terminals that are open as Mac or Windows applications use the OS execution environment.

Therefore, although it can be built properly with the GUI,

./gradlew assemble

That's why it fails when you try to build with a command such as.

If you can build with GUI, you can also run Terminal in the execution environment of Android Studio.

It seems that you should pass the environment variable Path to .bashrc or .zshrc.

export PATH=$PATH:/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home/bin
export JAVA_HOME=/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home

Then, depending on the version of Android Studio, it will be possible to start from Terminal with the execution environment of the appropriate Java version.

By the way, it was 1.8.0_212-release in Android Studio 3.6-RC1.

Download different versions of the JDK

Even if it is a different version, the 1.8.0 series seems to be good from the above Android Studio execution environment. It's Java 8.

[Oracle HP](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html Install from downloads / jdk8-downloads-2133151.html)).

There are many articles on the install procedure, so please refer to them.

I should have been able to go without creating an Oracle account because I recently needed to sign in.

Also, the display name may be 8u *** in the form of Java SE Development Kit 8u241, but that is the 1.8.0 series.

After installing, take a look at the version list of the JDK you have installed.

/usr/libexec/java_home -V

Once confirmed, set the JDK version to an environment variable.

export JAVA_HOME=`/usr/libexec/java_home -v {java_version}

For {java_version}, enter the version you confirmed earlier.

After that, whether you can set it safely

java -version

Check with and if you can set it properly, it's OK.

References

https://qiita.com/mas0061/items/2fe9333f045800d00b5c

https://qiita.com/kkkkan/items/f9595107a2a9153d1c60

https://github.com/acroquest/javabook-support/issues/49

Recommended Posts

I stumbled on the Java version in Android Studio, so I will summarize it
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
I can't remember the text file input / output in Java, so I summarized it.
I passed Ruby Silver (June 2020), so I will summarize it.
A super beginner has completed the Spring introductory book, so I will summarize it in my own way
[Java] I studied polymorphism, so I will summarize how to use it and its merits.
[Java] [javaSliver] The interface and abstract classes are complicated, so I will summarize them.
Refer to C ++ in the Android Studio module (Java / kotlin)
I noticed that I am developing Java FW in the mono repo, so I will consider the operation.
I made the "Sunshine Ikezaki game" I saw on Twitter in Java.
I opened the menu bar (option menu) on Android and saw it.
The corretto I put in Homebrew disappeared after updating, so I fixed it.
I tried the new era in Java
What wasn't fair use in the diversion of Java APIs on Android
Java to C and C to Java in Android Studio
I received the data of the journey (diary application) in Java and visualized it # 001
Place Java project using database on the server created in VPS so far
Summarize the life cycle of Java objects to be aware of in Android development
Impressions and doubts about using java for the first time in Android Studio
3 ways to import the library in Android Studio
Use the JDK used in Android Studio in the terminal
I stumbled on Android DataBinding + Kotlin (more BindingAdapter)
I touched on the new features of Java 15
Get your version number in the Android app
Try the free version of Progate [Java I]
In Java Try-with-Resources, even if you return in the try clause, it will be closed properly, so let's return without worrying
Apple Silicon compatible version of Docker Desktop (Preview) has been released to the public, so I will try it
[Android development] Get an image from the server in Java and set it in ImageView! !!
I took Oracle Java Bronze SE 7/8 now, so I will write it as an article
I stumbled when I tried using neo4j in the jenv environment, so make a note
The handling of Java Future is too dull, so I will try various ideas.
[Android studio / Java] What you don't understand when you touch it for the first time
I got a cannot resolve symbol in Android Studio
[Android Studio] [Java] How to fix the screen vertically
[Android Studio] I want to use Maven library on Android
[Introduction] Display Android Studio Hello World on the emulator
I want to simplify the log output on Android
Summarize the additional elements of the Optional class in Java 9
What I stumbled upon in the ActiveModel :: Serializer test
I finished watching The Rose of Versailles, so I tried to reproduce the ending song in Java
I got stuck in launching Unreal Enigine 4 on an AWS Ubuntu instance, so I summarized it
Notes in Android studio
Will programs get faster just by increasing the Java version?
I immediately stumbled on the standard input method with AtCoder.
parquet-tools gives java.lang.ExceptionInInitializerError, so I made it work with java8
[Java] ArrayList → Should I specify the size in array conversion?
I tried to summarize the basics of kotlin and java
[Android, Java] Convenient method to calculate the difference in days
Java SE 13 (JSR388) has been released so I tried it
What I did in the version upgrade from Ruby 2.5.2 to 2.7.1
You are currently using Java 6. Solution in Android Studio Gradle
How to switch Java in the OpenJDK era on Mac
I tried using the CameraX library with Android Java Fragment
I want to simplify the conditional if-else statement in Java