fix(tooling-api): project initialization failure when the project contains a Java library module

This happens due to the use of relocated packages in AndroidIDE's Java Compiler API. The 'JavaModuleCompilerSettings' class references the 'javax.lang.model.SourceVersion.RELEASE_11' enum.
However, in AndroidIDE, the SourceVersion class has the package name 'jdkx.lang.model'.

The project compiles successfully as the ':subprojects:tooling-api-model' module is a Java library due to which, 'javax.lang.model.SourceVersion' can be referenced without any errors.
However at runtime, there is no such class and hence the 'NoClassDefFoundError' is thrown. This exception is silently logged to the error stream by the JSONRpc protocol and hence it
cannot be seen in the IDE logs.

This closes #875.
This commit is contained in:
Akash Yadav
2023-03-18 13:48:19 +05:30
parent e56229c05d
commit 1730d0ae67
2 changed files with 7 additions and 3 deletions
Binary file not shown.
@@ -18,7 +18,6 @@
package com.itsaky.androidide.tooling.api.model
import com.itsaky.androidide.builder.model.IJavaCompilerSettings
import javax.lang.model.SourceVersion
/**
* Compiler settings for [JavaModule].
@@ -29,8 +28,13 @@ class JavaModuleCompilerSettings(
override val javaSourceVersion: String,
override val javaBytecodeVersion: String
) : IJavaCompilerSettings(), java.io.Serializable {
private val serialVersionUID = 1L
internal constructor() : this(SourceVersion.RELEASE_11.name, SourceVersion.RELEASE_11.name)
// IMPORTANT
// Do not use javax.lang.model.SourceVersion reference here
// When running on Android, this class is preset as jdkx.lang.model.SourceVersion
// Using the 'javax' reference will result a 'ClassNotFoundException' while deserializing the
// JSONRpc data received from the Tooling API server
internal constructor() : this("RELEASE_11", "RELEASE_11")
}