Skip to content

fix(gradle-9): unable to resolve class XmlParser for Groovy 4.x#1896

Merged
erisu merged 1 commit intomasterfrom
fix/gradle-xmlparser
Mar 19, 2026
Merged

fix(gradle-9): unable to resolve class XmlParser for Groovy 4.x#1896
erisu merged 1 commit intomasterfrom
fix/gradle-xmlparser

Conversation

@erisu
Copy link
Copy Markdown
Member

@erisu erisu commented Feb 26, 2026

Platforms affected

n/a

Motivation and Context

Fix unable to resolve class XmlParser:

Script '/Users/cordova/testProject/platforms/android/CordovaLib/cordova.gradle' line: 135

Could not compile script '/Users/cordova/testProject/platforms/android/CordovaLib/cordova.gradle'.
> startup failed:
  script '/Users/cordova/testProject/platforms/android/CordovaLib/cordova.gradle': 135: unable to resolve class XmlParser 
   @ line 135, column 12.
         return new XmlParser(false, false).parseText(xml)
                ^
  
  1 error

Description

Added following import to cordova.gradle

import groovy.xml.XmlParser

While this is unconfirmed, I beleive the XmlParser was originally was located in groovy.util.XmlParser and was deprecated and removed in 4.0.0. The new location for the XmlParser parser is groovy.xml.XmlParser which 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 t
  • platform add
  • build android
  • Open project in Android Studio Panda 1 without first build.

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.43%. Comparing base (6b17223) to head (81c6dc5).
⚠️ Report is 5 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@erisu erisu changed the title fix(gradle): unable to resolve class XmlParser for Groovy 4.x fix(gradle-9): unable to resolve class XmlParser for Groovy 4.x Feb 26, 2026
Copy link
Copy Markdown
Contributor

@GitToTheHub GitToTheHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.:

Image

When I do cordova prepare before opening the project, this error is only showed sometimes, but I always get the warning:

Bildschirmfoto 2026-02-26 um 13 07 02

When I do cordova build before opening the project in Android Studio Panda 1, I get no warnings and errors.

@GitToTheHub
Copy link
Copy Markdown
Contributor

Would it make sense to automatically call cordova build after the android platform was added?

@erisu erisu added this to the 15.0.1 milestone Mar 6, 2026
@erisu erisu merged commit 9ae489b into master Mar 19, 2026
21 checks passed
@erisu erisu deleted the fix/gradle-xmlparser branch March 19, 2026 00:58
@erisu
Copy link
Copy Markdown
Member Author

erisu commented Mar 19, 2026

and open it in Android Studio Panda 1, I get the error: Invalid Gradle JDK configuration found.:

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 cordova platform add, as well as running cordova prepare after adding the platform.

Since this PR is unrelated to that issue, I went ahead and merged it.

Would it make sense to automatically call cordova build after the android platform was added?

I am not entirely sure if we want to run a full cordova build immediately after adding the platform. However, I believe the Gradle wrapper should be created at least after the platform is added.

But for now, I believe the recommendation has always been to run cordova build after adding a platform.

@GitToTheHub
Copy link
Copy Markdown
Contributor

GitToTheHub commented Mar 19, 2026

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 cordova platform add, as well as running cordova prepare after adding the platform.

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.

I am not entirely sure if we want to run a full cordova build immediately after adding the platform. However, I believe the Gradle wrapper should be created at least after the platform is added.

But for now, I believe the recommendation has always been to run cordova build after adding a platform.

This makes the development more difficult because you always have to remember to make a cordova build android for the android platform if you want to open it in Android Studio after you added the platform. For iOS this is not needed, but for some plugins you have to make a cordova prepare ios. I find this is not very clean. The best would be if everything is setup when cordova platform add is called or cordova plugin add. cordova build, as I undertand, should make a runnable executable for the device or emulator, not a functionable project for the IDE. This is very inconsistent when cordova platform add creates a half functional Android Studio project but cordova build is required to create a full functional IDE project. I think this should be improved.

@breautek
Copy link
Copy Markdown
Contributor

This is very inconsistent when cordova platform add creates a half functional Android Studio project but cordova build is required to create a full functional IDE project. I think this should be improved.

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 tools subfolder, which acts as a standalone android project (it has it's own settings.gradle) and it's entire purpose is to decouple the android gradle project from the Android SDK -- so that we can request a gradle wrapper, using the system gradle version that the user has installed, to get a gradle wrapper at the version the project wants.

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.

@GitToTheHub
Copy link
Copy Markdown
Contributor

I'm not so deep with Gradle but thought, that an Android project can specify the required Gradle version.
I created a new Android Project with Android Studio (not with Cordova) an see, there is also a gradle wrapper by default:

image

If an Android Studio project is using gradle wrapper in this way, maybe Cordova can do it in the same way?

@breautek
Copy link
Copy Markdown
Contributor

If an Android Studio project is using gradle wrapper in this way, maybe Cordova can do it in the same way?

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.

@GitToTheHub
Copy link
Copy Markdown
Contributor

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 cordova run android when trying to target a specific emulator, or I need Logcat. I don't understand currently the technical stack behind Gradle and Android Studio but it would be good to have a workable Android Studio project after cordova platform add android is executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants