Android TargetSDK 31 的离子构建失败:CordovaLib:compileReleaseJavaWithJavac FAILED

Dan*_*ead 3 android cordova ionic-framework

我已经解决了这个问题,只是将其放在这里供任何遇到同样问题的人使用:

当我尝试上传 Ionic 应用程序的 Android 版本时,Google Play 开发者控制台告诉我,我需要 31 的 Target SDK。

我可以通过更新我的config.xml这条线来更新它

 <preference name="android-targetSdkVersion" value="31" />
Run Code Online (Sandbox Code Playgroud)

但是,当我构建我的应用程序时,它会失败并出现以下错误,并且没有任何真正指示下一步该做什么

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
Run Code Online (Sandbox Code Playgroud)

Dan*_*ead 7

我通过更新计算机上的 Java 版本解决了这个问题。

之前我使用的是 1.8.0 版本,将 Java 升级到版本 11 后构建成功。

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

我还更新了我的 gradle 版本,但不确定这是否有必要

brew upgrade gradle