commons-app / apps-android-commons

The Wikimedia Commons Android app allows users to upload pictures from their Android phone/tablet to Wikimedia Commons
https://commons-app.github.io/
Apache License 2.0
987 stars 1.18k forks source link

Build error "jdk.compiler does not export com.sun.tools.javac.main to unnamed module" #5393

Open nicolas-raoul opened 8 months ago

nicolas-raoul commented 8 months ago

Since updating to Java 21.0.1 (OpenJDK Runtime Environment Zulu21.30+15-CA) I get this error when running ./gradlew clean installProdDebug:

> Task :app:kaptGenerateStubsProdDebugKotlin FAILED
e: java.lang.IllegalAccessError: superclass access check failed: class org.jetbrains.kotlin.kapt3.base.javac.KaptJavaCompiler (in unnamed module @0xde12700) cannot access class com.sun.tools.javac.main.JavaCompiler (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.main to unnamed module @0xde12700
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524)
        at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427)
        at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:714)
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.contextForStubGeneration(Kapt3Extension.kt:296)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:175)
        at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:106)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:116)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:126)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:100)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:265)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:53)
        at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:256)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:99)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:58)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:158)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:99)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:47)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
        at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:475)
        at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:125)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:373)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:318)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.rebuild(IncrementalCompilerRunner.kt:114)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:207)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:79)
        at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:625)
        at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:101)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1746)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:714)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:598)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:844)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:721)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:720)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1583)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptGenerateStubsProdDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Internal compiler error. See log for more details

I tried updating kotlin-gradle-plugin to 1.9.20 but the I get a deprecation error.

Strangely I still get it when running JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/ ANDROID_SDK_ROOT=/Users/nicolasraoul/Library/Android/sdk ./gradlew clean installProdDebug

nicolas-raoul commented 7 months ago

Now it works with the same JDK version 17, not sure what was happening.

nicolas-raoul commented 6 months ago

Now failing with this error again. I don't think I changed my Java configuration on my machine, though there might have been a silent update.

nicolas-raoul commented 6 months ago

I tried these changes:

diff --git a/app/build.gradle b/app/build.gradle
index c309a52b2..a7dcfafaa 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -164,10 +164,10 @@ dependencies {
     //OSMDroid
     implementation ("org.osmdroid:osmdroid-android:$OSMDROID_VERSION")
     constraints {
-        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
+        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.20") {
             because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
         }
-        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
+        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.20") {
             because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
         }
     }
@@ -352,8 +352,8 @@ android {

     compileOptions {
-        sourceCompatibility JavaVersion.VERSION_1_8
-        targetCompatibility JavaVersion.VERSION_1_8
+        sourceCompatibility JavaVersion.VERSION_17
+        targetCompatibility JavaVersion.VERSION_17
     }

     buildToolsVersion buildToolsVersion
diff --git a/data-client/build.gradle b/data-client/build.gradle
index 3b2a33cd1..43fcd37b2 100644
--- a/data-client/build.gradle
+++ b/data-client/build.gradle
@@ -14,7 +14,7 @@
 // email - me@dmitrybrant.com

 buildscript {
-    ext.kotlin_version = '1.7.20'
+    ext.kotlin_version = '1.9.20'
     repositories {
         mavenCentral()
         google()
@@ -59,8 +59,8 @@ android {
         abortOnError false
     }
     compileOptions {
-        sourceCompatibility = '1.8'
-        targetCompatibility = '1.8'
+        sourceCompatibility = '17'
+        targetCompatibility = '17'
     }
     namespace 'org.wikipedia.dataclient'
 }
@@ -89,10 +89,10 @@ dependencies {
     testImplementation "commons-io:commons-io:2.6"

     constraints {
-        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
+        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.20") {
             because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
         }
-        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
+        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.20") {
             because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
         }
     }
diff --git a/gradle.properties b/gradle.properties
index f0646307c..3fe5eff6c 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -17,7 +17,7 @@ org.gradle.jvmargs=-Xmx1536M
 org.gradle.caching=true
 android.enableR8.fullMode=false

-KOTLIN_VERSION=1.7.20
+KOTLIN_VERSION=1.9.20
 BUTTERKNIFE_VERSION=10.1.0
 LEAK_CANARY_VERSION=2.10
 DAGGER_VERSION=2.23

but get this error:

Task :wikimedia-data-client:compileDebugKotlin FAILED e: The Android extensions ('kotlin-android-extensions') compiler plugin is no longer supported. Please use kotlin parcelize and view binding. More information: https://goo.gle/kotlin-android-extensions-deprecation

nicolas-raoul commented 6 months ago

I am getting the same error with a very old code version from 3 months ago (2ddb6b2e5ea0643aa46f0ad20bd7b6862b4e1e79) despite the fact that I have build it (and many other since) successfully in the past.

So this seems to be related to a change on my machine rather than a change in the app's code.

rohit9625 commented 5 months ago

What is this error about? Does it occur when upgrading the JDK version to 21.

Pujan92 commented 5 months ago

@nicolas-raoul is it fixed for you as I am facing the same error?

nicolas-raoul commented 4 months ago

@Pujan92 I am not facing this error anymore, but honestly I am not sure why. If you find, please let us know here. :-)

Pujan92 commented 4 months ago

@nicolas-raoul Thanks, I downgraded the kotlin version from 1.8.10 to 1.6.20 and it gets fixed for now.

MehulKK commented 4 months ago

Its seems fixed and working for me with below kotlin and gradle configuration.

distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip classpath 'com.android.tools.build:gradle:7.0.0'

Kotlin version : 1.6.20

With JDK version 17

rohit9625 commented 4 months ago

But it's not working with the newer version. Did you find any reason why?

DSDrachmann commented 1 month ago

I was on kotlin version 1.9.0 and had the same issue. I upgraded to kotlin version 1.9.22 and it seems to have fixed it.

mXaln commented 1 week ago

I was on org.jetbrains.kotlin.android version 1.9.20 and had that error. Only @DSDrachmann solution worked for me.

DSDrachmann commented 6 days ago

I was on org.jetbrains.kotlin.android version 1.9.20 and had that error. Only @DSDrachmann solution worked for me.

That's good to hear! a small fix but glad that you also got past that problem