javanetbeanscodenameone

When using Gradle 8, you must set the JAVA17_HOME environment variable to the location of a Java 17 JDK


I’ve been unable to build codenameone Android Gradle Projects since upgrading on NetBeans 12.6 to codenameone-maven-plugin:7.0.150. Receiving the following error message:

Generating android gradle Project to /Users/mike/IT/NetBeansProjects/myapp/android/target/myapp-android-1.0-SNAPSHOT-android-source...
Starting android project builder...
Failed to build Android project with error: When using gradle 8, you must set the JAVA17_HOME environment variable to the location of a Java 17 JDK


com.codename1.builders.BuildException: When using gradle 8, you must set the JAVA17_HOME environment variable to the location of a Java 17 JDK
    at com.codename1.builders.AndroidGradleBuilder.getGradleJavaHome (AndroidGradleBuilder.java:440)
    at com.codename1.builders.AndroidGradleBuilder.build (AndroidGradleBuilder.java:489)
    at com.codename1.maven.CN1BuildMojo.doAndroidLocalBuild (CN1BuildMojo.java:847)
    at com.codename1.maven.CN1BuildMojo.createAntProject (CN1BuildMojo.java:562)
    at com.codename1.maven.CN1BuildMojo.executeImpl (CN1BuildMojo.java:116)
    at com.codename1.maven.AbstractCN1Mojo.execute (AbstractCN1Mojo.java:195)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:61)

As Shai suggested, I created MyTestApp from Codename One Initializr at start.codenameone.com.

It runs fine from the command line on JDK 17 but fails on the android build ./build.sh android_source

Does that mean there is a compatibility issue with JDK 17 and I should be using a different Java JDK? Here’s a few key lines of output:

[INFO] <<< codenameone-maven-plugin:7.0.86:build (build-android) < package @ mytestapp-android <<<
[INFO] 
[INFO] 
[INFO] --- codenameone-maven-plugin:7.0.86:build (build-android) @ mytestapp-android ---
[INFO] Running ANT build target android-source
[INFO] Generating android gradle Project to /Users/mike/IT/NetBeansProjects/mytestapp/android/target/mytestapp-android-1.0-SNAPSHOT-android-source...
[INFO] Starting android project builder...
[INFO] Executing with timeout -1
[INFO] Exception in thread "main" 
[INFO] java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)

[INFO] Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 5 more

[INFO] Process return code is 1
[INFO] Executing with timeout -1
[INFO] 

[INFO] ------------------------------------------------------------
Gradle 6.8.3

[INFO] ------------------------------------------------------------

Build time:   2021-02-22 16:13:28 UTC

[INFO] Revision:     9e26b4a9ebb910eaa1b8da8ff8575e514bc61c78

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
[INFO] 
JVM:          17.0.11 (Oracle Corporation 17.0.11+7-LTS-207)
OS:           Mac OS X 14.3.1 aarch64


[INFO] Process return code is 0
[INFO] TargetSDKVersion= android:targetSdkVersion="31" 
[INFO] Creating AndroidStudioProject from template
[INFO] Executing: 
[INFO] /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin/java -Dretrolambda.inputDir=/Users/mike/IT/NetBeansProjects/mytestapp/android/target/codenameone/antProject/dist/android-build/Classes -Dretrolambda.classpath=/Users/mike/IT/NetBeansProjects/mytestapp/android/target/codenameone/antProject/dist/android-build/Classes:/Users/mike/.m2/repository/com/codenameone/codenameone-core/7.0.150/codenameone-core-7.0.150.jar -Dretrolambda.outputDir=/Users/mike/IT/NetBeansProjects/mytestapp/android/target/codenameone/antProject/dist/android-build/Classes_retrolamda -Dretrolambda.bytecodeVersion=49 -Dretrolambda.defaultMethods=true -jar /Users/mike/.m2/repository/net/orfjackal/retrolambda/retrolambda/2.5.7/retrolambda-2.5.7.jar 
[INFO] Executing with timeout -1
[INFO] Retrolambda 2.5.7

[INFO] 00:00  INFO: Bytecode version: 49 (Java 5)

[INFO] 00:00  INFO: Default methods:  true
00:00  INFO: Input directory:  /Users/mike/IT/NetBeansProjects/mytestapp/android/target/codenameone/antProject/dist/android-build/Classes
00:00  INFO: Output directory: /Users/mike/IT/NetBeansProjects/mytestapp/android/target/codenameone/antProject/dist/android-build/Classes_retrolamda

[INFO] 00:00  INFO: Classpath:        [/Users/mike/IT/NetBeansProjects/mytestapp/android/target/codenameone/antProject/dist/android-build/Classes, /Users/mike/.m2/repository/com/codenameone/codenameone-core/7.0.150/codenameone-core-7.0.150.jar]
00:00  INFO: Included files:   all
00:00  INFO: JVM version:      17.0.11
00:00  INFO: Agent enabled:    false
00:00  INFO: javac hacks:      false

[INFO] 00:00 ERROR: Failed to run Retrolambda
java.lang.IllegalStateException: Cannot initialize dumper; unexpected JDK implementation. Please run Retrolambda using the Java agent (enable forking in the Maven plugin).
    at net.orfjackal.retrolambda.lambdas.LambdaClassDumper.install(LambdaClassDumper.java:38)
    at net.orfjackal.retrolambda.Retrolambda.run(Retrolambda.java:67)
    at net.orfjackal.retrolambda.Main.main(Main.java:28)
    Suppressed: java.lang.RuntimeException: java.lang.IllegalAccessException: class net.orfjackal.retrolambda.lambdas.LambdaClassDumper cannot access a member of class java.lang.invoke.InnerClassLambdaMetafactory (in module java.base) with modifiers "private static final"
        at net.orfjackal.retrolambda.lambdas.LambdaClassDumper.uninstall(LambdaClassDumper.java:48)
        at net.orfjackal.retrolambda.lambdas.LambdaClassDumper.close(LambdaClassDumper.java:55)
        at net.orfjackal.retrolambda.Retrolambda.run(Retrolambda.java:102)
        ... 1 more

Solution

  • Changing the Java 17 folder name from jdk-17.jdk to jdk-17.0.11.jdk fixed the problem.

    Originally

    JDK 17 Foldername:

    /Library/Java/JavaVirtualMachines/jdk-17.jdk
    

    In .zshrc file:

    export JAVA17_HOME='/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home'
    

    echo $JAVA17_HOME:

    /Library/Java/JavaVirtualMachines/jdk-17.jdk
    

    /Contents/Home was missing from echo'd path

    Revised

    JDK 17 Foldername:

    /Library/Java/JavaVirtualMachines/jdk-17.0.11.jdk
    

    In .zshrc file:

    export JAVA17_HOME='/Library/Java/JavaVirtualMachines/jdk-17.0.11.jdk/Contents/Home'
    

    echo $JAVA17_HOME:

    /Library/Java/JavaVirtualMachines/jdk-17.0.11.jdk/Contents/Home
    

    /Contents/Home doesn't get clipped!