Android SDK Manager throws Exception [Java 11 issue. Please Read Description] - flutter

I'm trying to set up flutter on my Ubuntu 19.10 machine.
When I run flutter doctor --android-licenses It prompts me to update the SDK like so -
A newer version of the Android SDK is required. To update, run:
/home/<username>/Android/SDK/tools/bin/sdkmanager --update
When I run it, I encounter an Exception - java.lang.NoClassDefFoundError
This answer suggests changing DEFAULT_JVM_OPTS in sdkmanager to
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" --add-modules java.xml.bind'
This seems to work in Java 9/10. However, I use Java 11 and unfortunately the java.xml.bind module and java.se.ee module has been discontinued from Java 11 -
java version "11.0.6" 2020-01-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.6+8-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.6+8-LTS, mixed mode)
Is there a way to fix this in Java 11? Or do I have to downgrade to Java 9/10?

flutter supports java 1.8
so, try install java 1.8

Related

sdkman! How to manage pre-existing JDK?

I wanted to try Java 19 and have easy switching back to the Java 17 that I have already installed.
So, I installed sdkman but it knows nothing of the previous Java.
Found the "install local" command, used it to link the java 17 location to a unique name and sdkman seems happy, as it reports "Done installing!".
After that the "sdk current java" returns "Not using any version of java".
So then I tried "sdk use java [my unique name]. That was also accepted.
But still the "sdk current java" response is unchanged.
Have I misunderstood how this should work? I want to be sure sdkman knows what is there already before I add another Java.
Thanks for your advice!
Terminal commands follow (Kubuntu 22.04)
john#NUC8i3BEH:~$ java -version
openjdk version "17.0.4.1" 2022-08-12 LTS
OpenJDK Runtime Environment (build 17.0.4.1+1-LTS)
OpenJDK 64-Bit Server VM (build 17.0.4.1+1-LTS, mixed mode, sharing)
john#NUC8i3BEH:~$ sdk install java 17.0.4.1-Bellsoft /usr/lib/jvm/bellsoft-java17-full-amd64
Invalid version! 17.0.4.1-Bellsoft with length 17 exceeds max of 15!
john#NUC8i3BEH:~$ sdk install java 17.0.4.1-Bell /usr/lib/jvm/bellsoft-java17-full-amd64
Linking java 17.0.4.1-Bell to /usr/lib/jvm/bellsoft-java17-full-amd64
Done installing!
john#NUC8i3BEH:~$ sdk list
john#NUC8i3BEH:~$ sdk current
No candidates are in use
john#NUC8i3BEH:~$ sdk current java
Not using any version of java
john#NUC8i3BEH:~$ sdk list java
john#NUC8i3BEH:~$ sdk use java 17.0.4.1-Bell
==== BROADCAST =================================================================
* 2022-09-21: neo4jmigrations 1.12.0 available on SDKMAN! https://github.com/michael-simons/neo4j-migrations/releases/tag/1.12.0
* 2022-09-21: micronaut 3.7.0 available on SDKMAN!
* 2022-09-20: quarkus 2.12.3.Final available on SDKMAN! https://github.com/quarkusio/quarkus/releases/tag/2.12.3.Final
================================================================================
Setting java version 17.0.4.1-Bell as default.
Using java version 17.0.4.1-Bell in this shell.
john#NUC8i3BEH:~$ java -version
openjdk version "17.0.4.1" 2022-08-12 LTS
OpenJDK Runtime Environment (build 17.0.4.1+1-LTS)
OpenJDK 64-Bit Server VM (build 17.0.4.1+1-LTS, mixed mode, sharing)
john#NUC8i3BEH:~$ sdk current java
Not using any version of java
john#NUC8i3BEH:~$
OK, I should have tried harder.
I installed Java 19 with sdkman then the command "sdk default java [my old version]" switches back as required.

Building Kotlin Multiplatform app with Xcode Cloud

as Apple announced that Xcode Cloud is now available for all developers, I tried to set it up for a Kotlin Multiplatform project. The start was a little bit hard tbh. Currently I am facing following problem during a simple test action:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Command PhaseScriptExecution failed with a nonzero exit code
So I tried to install a jdk during the ci_post_clone.sh phase. The output of java -version after the installation on the Xcode Cloud is the following:
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
Installed java
also ./gradlew -v output:
Showing All Messages
------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17.0.2 (Oracle Corporation 17.0.2+8-86)
OS: Mac OS X 12.4 x86_64
Nevertheless, I still get the same error. Is this maybe a restriction by Apple?
Any ideas?

java web start fails to locate java runtime

Hi I am trying to run javaws but it prompts:
To open this Web Start application you need to download the Java Runtime Environment.
I am sure JRE is installed, maybe javaws does not find it, how do I fix that?
Johns-MacBook-Pro:~ johnmactavish$ java --version
java 13.0.2 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
Johns-MacBook-Pro:~ johnmactavish$ javaws
No Java runtime present, requesting install.
Unable to locate a Java Runtime to invoke.
Johns-MacBook-Pro:~ johnmactavish$
Java Web Start (javaws) was deprecated in Java 9 and removed in Java 11.
As you are using java 13, you can either downgrade from 13 to 8, or look for alternatives.
Perhaps an alternative such as https://openwebstart.com/ can help you out with that.
P.S: In case you're using tools to manage version such as sdkman or such, there might be the case where it's also not available in SDKs # version 8 provided by sdkman.

Flutter and java sdk

i've reached a brickwall with java.
$ flutter doctor --android-licenses
A newer version of the Android SDK is required. To update, run:
/Users/simonhampton/Library/Android/sdk/tools/bin/sdkmanager --update
$ /Users/simonhampton/Library/Android/sdk/tools/bin/sdkmanager --update
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
I have
$ java --version
java 12.0.2 2019-07-16
Java(TM) SE Runtime Environment (build 12.0.2+10)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)
I feel like I've installed everything possible - jre, jdk, dfk, openadk,....and nothing works. Is there a guaranteed solution to make java work?
Try it with java 8 SDK or versions before it, Not after this version.

JMC Java Flight Recorder not enabled

I am using spring tool suite with the java mission control plugin to start an app which I would like to monitor using the JFR. I added -XX:+UnlockCommercialFeatures -XX:+FlightRecorder to the SpringToolSuite4.ini and additionally set JAVA_OPTS with those two flags (both of which is not necessary if I understand it correctly) and -XX:+FlightRecorder in Run configurations > Arguments > VM arguments of the application to be monitored. When adding both flags as well to the run configuration the application cannot be started with the openJdk.
After starting the application in the JVM Browser when selecting the Flight Recorder I get the following exception.
java.lang.RuntimeException: Flight Recorder features are not enabled. To enable this you need to use a Java 7u4 or later JVM started with -XX:+UnlockCommercialFeatures -XX:+FlightRecorder.
at com.oracle.jmc.flightrecorder.controlpanel.ui.FlightRecorderProvider.refresh(FlightRecorderProvider.java:105)
at com.oracle.jmc.browser.views.JVMBrowserView$1.run(JVMBrowserView.java:98)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: com.oracle.jmc.rjmx.services.jfr.FlightRecorderException: Flight Recorder features are not enabled. To enable this you need to use a Java 7u4 or later JVM started with -XX:+UnlockCommercialFeatures -XX:+FlightRecorder.
at com.oracle.jmc.flightrecorder.controlpanel.ui.FlightRecorderProvider.getService(FlightRecorderProvider.java:161)
at com.oracle.jmc.flightrecorder.controlpanel.ui.FlightRecorderProvider.refreshRecordings(FlightRecorderProvider.java:117)
at com.oracle.jmc.flightrecorder.controlpanel.ui.FlightRecorderProvider.refresh(FlightRecorderProvider.java:94)
... 7 more
I tried it with the following java versions.
$ java -version
openjdk version "11.0.2" 2018-10-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.2+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.2+7, mixed mode)
or with the JDK from oracle
$ java -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
For none of the above mentioned JDK's there is a jmc.exe which was there with java 8. Is that part of the plugin?
How can I get this running?
IIRC, Java 11 requires JMC 7 to be able to start and view recordings.
JMC 7 EA builds are expected to appear here soon - https://jdk.java.net/jmc/
In the meantime you can build JMC yourself, see http://hg.openjdk.java.net/jmc/jmc7/ (or github, not exactly sure which version it is synced to - https://github.com/JDKMissionControl/jmc) and the README on how to build.
You can start recordings using JVM command line flags, and using jcmd, and parse the recordings using https://docs.oracle.com/en/java/javase/11/docs/api/jdk.jfr/jdk/jfr/consumer/package-summary.html