fix(gradle-9): unable to resolve class XmlParser for Groovy 4.x#1896
fix(gradle-9): unable to resolve class XmlParser for Groovy 4.x#1896
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1896 +/- ##
=======================================
Coverage 61.43% 61.43%
=======================================
Files 24 24
Lines 4922 4922
=======================================
Hits 3024 3024
Misses 1898 1898 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
It works now everything, when the platform is added and cordova prepare is called after. When I just add the platform by cordova platform add and open it in Android Studio Panda 1, I get the error: Invalid Gradle JDK configuration found.:
When I do cordova prepare before opening the project, this error is only showed sometimes, but I always get the warning:
When I do cordova build before opening the project in Android Studio Panda 1, I get no warnings and errors.
|
Would it make sense to automatically call |
I have encountered this error once before, but have not seen it since. I tried deleting and recreating the project multiple times. I also attempted opening the project without running any commands after Since this PR is unrelated to that issue, I went ahead and merged it.
I am not entirely sure if we want to run a full But for now, I believe the recommendation has always been to run |
I also got this error very rarely and the last time I used the latest cordova-android platform I didn't get this error any more.
This makes the development more difficult because you always have to remember to make a |
I do agree but I also agree with Erisu that we might not want to do a full build on platform add. But platform add should generate functional IDE project. If I recall correctly we have a dummy project in a The reason why we need to decouple from the Android SDK for this step is because the Android SDK will apply gradle version constraints preventing you from executing the gradle wrapper task. Which means if you load in the Android SDK into the build script, the installed system gradle version must be satisfiable by Android SDK which kinda defeats the purpose of using a wrapper... So we have a dummy project allowing a much broader version range of gradle, to be used to get the gradle wrapper. Then to make Android Studio IDE recognize that the wrapper is installed for its own project, we copy the gradle wrapper files up to the main android project. This is all to work around the "Gradle" way of doing things, which they say you should check in the gradle wrapper, including it's binary content into the repository. However if you accept that practice, you open yourself up to the XZ problem... as it can be very easy to sneak and hide malicious code in binary files. |
It does already -- The wrapper is downloaded/installed by Gradle itself. Instead of using the main projects gradle build environment to install the wrapper, which only supports a fairly limited gradle version range... we use an empty gradle build script, which is that "tools" project I mentioned. The wrapper gets installed inside the tools project. Then we simply copy the wrapper files up to the main project so that the Android IDE finds and uses that wrapper. Android Studio does ship with its own gradle -- so it doesn't run into the version conflicts cause it basically always has an acceptable gradle version builtin. But that gradle is not shipped as a standalone executable, it's a java library that Android Studio uses to do gradle tasks programmatically -- so we can't really take advantage of that. And even if it was a standalone executable -- using it would make a new dependency on Android Studio, Cordova should be usable with the android sdk tools alone without android studio. |
|
Thanks for the explanation. I understand, that Cordova should be able to build without using Android Studio and this is good. It would be cool if Android Studio is not needed so much, but I have currently problems with using |

Platforms affected
n/a
Motivation and Context
Fix
unable to resolve class XmlParser:Description
Added following import to
cordova.gradleWhile this is unconfirmed, I beleive the XmlParser was originally was located in
groovy.util.XmlParserand was deprecated and removed in 4.0.0. The new location for the XmlParser parser isgroovy.xml.XmlParserwhich also existed in version 3.0.0.I believe its safe to add this import to resolve the issue for Gradle 9.0 (Groovy 4) and continue to support Gradle 8.0 (Groovy 3).
Testing
npm tplatform addbuild androidChecklist
(platform)if this change only applies to one platform (e.g.(android))