ionic build failing for Android TargetSDK 31 :CordovaLib:compileReleaseJavaWithJavac FAILED


I already solved this issue, just putting this here for anyone struggling with the same issue:

When I attempted to upload the Android build of my Ionic app, Google Play Developer Console told me I needed a Target SDK of 31.

I was able to update this by updating my config.xml to have this line

 <preference name="android-targetSdkVersion" value="31" />

But then when I would build my app it would fail with the following error without any real indication of what to do next

Task :CordovaLib:compileReleaseJavaWithJavac FAILED
An exception has occurred in the compiler (1.8.0_202). Please file a bug against the Java compiler via the Java bug reporting page ( after checking the Bug Database ( for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class$NameImpl)
FAILURE: Build failed with an exception.
    * What went wrong:
    Execution failed for task ':CordovaLib:compileReleaseJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    * Get more help at
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
    You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
    BUILD FAILED in 3s
    22 actionable tasks: 2 executed, 20 up-to-date
    Command failed with exit code 1: /Users/danielread/Documents/GitHub/fitdegree/clients/apps/app/platforms/android/gradlew :app:bundleRelease -b /Users/danielread/Documents/GitHub/fitdegree/clients/apps/app/platforms/android/build.gradle


I was able to fix this by updating the version of Java on my computer.

Previously I was on version 1.8.0, after upgrading my Java to version 11 the build was successful.

I also updated my gradle version but not sure if this was neccessary

brew upgrade gradle

Answered By – DanielRead

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published