Error while compiling ionic app for android

Hey everyone! I’m building an app with Ionic (Ionic React) and I just got a basic version of the app working. I proceeded to run ionic capacitor add android, ionic capacitor copy android and ionic capacitor run android.

Note: Android studio is installed, android sdk is up-to-date, ANDROID_SDK_ROOT is set and PATH is configured.

ionic capacitor run android builds the project for web successfully, but when it tries to actually compile to android, I get the following error in the gradle task :app:processDebugMainManifest:

Unable to make field private final java.lang.String accessible: module java.base does not "opens" to unnamed module @4a712893

I tried re-running with --verbose but found no useful information.

The only similar issue I could find on the internet (Stack Overflow) seems to be unrelated to ionic and seems to be a discrepancy between two configuration files, both of which are by ionic CLI and not me in my case.

I hope someone knows what’s up here!

I think this is associated with your installed JDK version. Try changing the JDK location to something less than Java 16.

I made a few changes and now it works. I’m not exactly sure what it was that made it work, so here’s everything I did:

  • Upgraded Android Studio to the newest version (Arctic Fox)
  • Set Android Studio to use the internal jdk
  • Upgraded all SDK components
  • Removed all node_modules folders
  • Removed all package-lock.json and yarn.lock files
  • Configured Ionic CLI to use yarn as npm client
  • Upgraded capacitor CLI
  • Ran yarn

After doing all these things, it works like a charm!

1 Like