DEV Community

Cover image for Upgrade to Gradle JDK 11 on Github Actions
Kyle Foo
Kyle Foo

Posted on • Updated on

Upgrade to Gradle JDK 11 on Github Actions

Getting a compiler exception while building Android on Github Actions?

> Task :react-native-device-info:compileReleaseJavaWithJavac FAILED
An exception has occurred in the compiler (1.8.0_322). 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)
Enter fullscreen mode Exit fullscreen mode

In my case, react-native-device-info requires newer Gradle JDK during build. Hence, we need to update the JDK reference to version 11, not the default JDK 8 that uses version 1.8 compiler. See: https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#java

  • I'm using macos-11 Image on Github Actions.

In our local machine, we can do the upgrade here in Android Studio > Preferences > Build, Execution, Deployment > Build Tools > Gradle > Select Gradle JDK version:
Image description

On CI/CD, we can configure the environment to upgrade to JDK 11. For example, in Github Actions deployment steps, we add a upgrade step (Set up JDK 11):

jobs:
  deploy:
    name: Deploying to Playstore
    runs-on: macos-11
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2
      - name: Install Dependencies
        run: yarn
        working-directory: ${{ env.working-directory }}
      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          distribution: 'liberica'
          java-version: '11'
          cache: 'gradle'
Enter fullscreen mode Exit fullscreen mode

See https://github.com/actions/setup-java for more configuration regarding distribution, version and caching.

Top comments (0)