Open masranber opened 8 months ago
Hi, @masranber , Have your found any way to workaround this issue in existing projects in some way, while we wait for a fix?
In case it helps anyone, it has helped me to move the plugin to a new module of the application, of type "Java or Kotlin module"
@oscar-tu-lotero I haven't found a solution yet. The plugin is already in a separate module from the main application. Would you mind posting your project-level build.gradle and module-level build.gradle to see if I can replicate your fix?
Out of curiosity: does explicitly setting/providing targetVersion
help (as that should prevent code from entering 'problematic' if
block) ?
Issue
The plugin appears to be incompatible with newer versions the Android Gradle Plugin (8.0.0+ from what I can tell).
I'm using version 1.2.1 of the jsonschema2pojo plugin in an Android library. I'm currently in the process of upgrading the project from Android Gradle Plugin version 7.2.0 to 8.2.2, which also requires Gradle version >= 8.2.
After upgrading AGP and Gradle, building the project fails due to an exception in the
generateJsonSchema2Pojo
Gradle task:Here's the source code snippet where the exception is being thrown:
https://github.com/joelittlejohn/jsonschema2pojo/blob/72050f6b94d46d51d7c93c51e35383cdf5fc733f/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaAndroidTask.groovy#L63-L73
Steps to reproduce
1) Create a new, empty Android library project. 2) In 'project structure' menu in Android Studio, set AGP version to 8.2.2 and Gradle version to 8.2. 3) Apply the jsonschema2pojo plugin to the project. 4) Include a dummy json schema in the project (just so the generateJsonSchema2Pojo task runs). 4) Sync Gradle with project files. 5) Build project. 6) Build will fail with the above exception.
Potential solution
In newer versions of the Android Gradle Plugin
extension
is no longer a member of the classcom.android.build.gradle.LibraryPlugin
. Thecom.android.build.gradle.LibraryExtension
instance can instead be accessed via theandroid
property oforg.gradle.api.Project
that gets added by the AGP.Therefore, the following line:
should be changed to:
In my limited testing (basically just running the code directly in my build.gradle script) this appears to work in the latest AGP version as well as the version I was previously using (7.2.0).
I believe this issue also applies to Android apps (
com.android.application
projects). Since theandroid
property returns the correct project extension instance for the current project type (com.android.application
orcom.android.library
) the above code should also work forcom.android.application
projects.The
setTargetVersion
method would then look like:I'm not sure if this issue appears elsewhere in the source code.