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.
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.
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.
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.
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.
https://qiita.com/mas0061/items/2fe9333f045800d00b5c
https://qiita.com/kkkkan/items/f9595107a2a9153d1c60
https://github.com/acroquest/javabook-support/issues/49
Recommended Posts