Search code examples
androidcordovaionic-framework

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 (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$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 https://help.gradle.org
    
    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.
    
    See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings
    
    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

Solution

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

    https://www.oracle.com/java/technologies/downloads/#java11

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

    brew upgrade gradle