react-native-device-info: > Task :react-native-device-info:compileDebugJavaWithJavac FAILED

| Version | “react-native-device-info”: “^8.4.5” | | Affected OS | Android | | OS Version | 12 |

Current behavior

Hi, just updated my /android/build.gradle file

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 23
        compileSdkVersion = 31
        targetSdkVersion = 31
        ndkVersion = "21.4.7075529"
    }

and started getting

> Task :react-native-device-info:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings
213 actionable tasks: 17 executed, 196 up-to-date
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Note: /Users/icecapp/Documents/projects/rn/napp/node_modules/@notifee/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/icecapp/Documents/projects/rn/napp/node_modules/@react-native-async-storage/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/icecapp/Documents/projects/rn/napp/node_modules/@react-native-async-storage/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
An exception has occurred in the compiler (1.8.0_242). 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)
        at com.sun.tools.javac.util.Assert.error(Assert.java:133)
        at com.sun.tools.javac.code.TypeAnnotations.annotationType(TypeAnnotations.java:231)
        at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.separateAnnotationsKinds(TypeAnnotations.java:294)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-device-info:compileDebugJavaWithJavac'.
> 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

BUILD FAILED in 26s

    at makeError (/Users/icecapp/Documents/projects/rn/napp/node_modules/execa/index.js:174:9)
    at /Users/icecapp/Documents/projects/rn/napp/node_modules/execa/index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (/Users/icecapp/Documents/projects/rn/napp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
    at async Command.handleAction (/Users/icecapp/Documents/projects/rn/napp/node_modules/@react-native-community/cli/build/index.js:192:9)

Apologies in advance if this issue is not related to react-native-device-info

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17

Most upvoted comments

Started showing up after updating compileSdkVersion and targetSdkVersion to 31.

I fixed it by upgrading my selected Gradle JDK from 1.8 -> 11 (Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JDK)

Yep 31 api requires jdk11

I can’t be more clear on this one: It’s a JDK8 issue. You must use JDK11. Something is wrong in your local environment unfortunately. I won’t have time to correspond more.

It’s platform specific so there are no specific instructions. On mac I do this:

JDK_VERSION_WANTED="11" # https://adoptopenjdk.net/archive.html
# Check java install status
echo "Verifying installed Java Development Kit is openjdk$JDK_VERSION_WANTED"
if ! JAVA_VERSION=$(java -fullversion 2>&1) || [[ "$JAVA_VERSION" != *"openjdk full version \"11.0.11"* ]]; then
  echo "Java package should be adoptopenjdk$JDK_VERSION_WANTED but java version was $JAVA_VERSION"

  if [ "$(uname)" == "Darwin" ]; then
    echo "Installing openjdk$JDK_VERSION_WANTED via brew on macOS"
    brew untap adoptopenjdk/openjdk || true
    brew cleanup
    brew tap AdoptOpenJDK/openjdk
    brew install adoptopenjdk$JDK_VERSION_WANTED
    # shellcheck disable=SC2129
    echo "# --- Add JAVA_HOME items" >> "$HOME/.bash_profile"
    echo "JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-$JDK_VERSION_WANTED.jdk/Contents/Home" >> "$HOME/.bash_p
rofile"
    echo "export JAVA_HOME" >> "$HOME/.bash_profile"
    echo "PATH=\$JAVA_HOME/bin:\$PATH" >> "$HOME/.bash_profile"
    echo "export PATH" >> "$HOME/.bash_profile"
    echo "# --- End add JAVA_HOME items" >> "$HOME/.bash_profile"
    echo "!!! You will need to start a new Terminal session for $JDK_VERSION_WANTED to be in effect."
  else
    echo "You appear to not have openjdk full version $JDK_VERSION_WANTED installed, but it is required. Cannot proceed"
    exit 1
  fi
fi
# Check Android Studio status optionally?
echo "Verifying Android SDK installation"
if [ "$ANDROID_SDK_ROOT" == "" ]; then
  echo "ANDROID_SDK_ROOT environment variable not found. Configuring standard location"
  USER=$(whoami)
  if [ "$(uname)" == "Darwin" ]; then
    export ANDROID_SDK_ROOT="/Users/$USER/Library/Android/sdk"
  else
    export ANDROID_SDK_ROOT="/home/$USER/Android/Sdk"
  fi
  if ! [ -d "$ANDROID_SDK_ROOT/" ]; then
    echo "Configuring ANDROID_SDK_ROOT to standard location $ANDROID_SDK_ROOT failed"
    exit 1
  else
    echo "export ANDROID_SDK_ROOT=\"$ANDROID_SDK_ROOT\"" >> "$HOME/.bash_profile"
    echo "export PATH=\"\$ANDROID_SDK_ROOT/emulator:\$ANDROID_SDK_ROOT/platform-tools:\$ANDROID_SDK_ROOT/cmdline-tools/late
st/bin:\$ANDROID_SDK_ROOT/tools:\$PATH\"" >> "$HOME/.bash_profile"
    echo "Standard ANDROID_SDK_ROOT location found. Auto-configuration successful."
    echo "!!! You will need to start a new Terminal session before Android builds work."
  fi
fi

# Verify apkanalyzer (used for Android release build script) works after Java11 update
echo "Verifying Android command-line tools are up to date and in PATH"
if ! apkanalyzer > /dev/null 2>&1; then
  echo "Android command-line tools not set up correctly, fixing..."
  if ! [ -f "$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/apkanalyzer" ]; then
    echo "Android development has updated to Java 11, but your command-line tools don't support it."
    echo "You need to open Android Studio, start the SDK Manager tool, install command-line tools, re-run doctor"
    exit 1
  fi
  echo "export PATH=\"\$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:\$PATH\"" >> "$HOME/.bash_profile"
fi

…as part of a larget bash script I share with non-DevOps colleagues to get their machines converged.

Updating the JDK to the one recommended in RN docs solved the issue for me.

brew tap homebrew/cask-versions brew install --cask zulu11

https://reactnative.dev/docs/environment-setup#installing-dependencies

Alright so I inited a fresh new project, manually updated everything to jdk11, added few libs before react-native-device-info and I’m still getting the same error as original post

package.json

  "dependencies": {
    "@sentry/react-native": "^3.2.3",
    "promise": "^8.0.3",
    "react": "17.0.2",
    "react-native": "0.66.3",
    "react-native-bootsplash": "^4.0.1",
    "react-native-contacts": "^7.0.2",
    "react-native-country-picker-modal": "^2.0.0",
    "react-native-device-info": "^8.4.8",
    "react-native-flipper": "^0.121.1"
  },
> npx react-native info   
info Fetching system and libraries information...
System:
    OS: macOS 12.0.1
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
    Memory: 27.88 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.2.0 - ~/.asdf/installs/nodejs/16.2.0/bin/node
    Yarn: 1.22.10 - ~/.asdf/shims/yarn
    npm: 7.13.0 - ~/.asdf/installs/nodejs/16.2.0/bin/npm
    Watchman: 2021.11.15.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
    Android SDK:
      API Levels: 29, 30, 31
      Build Tools: 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0
      System Images: android-29 | Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7784292
    Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.12 - /usr/local/opt/openjdk@11/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.66.3 => 0.66.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

and then in Android Studio: Screen Shot 2021-11-25 at 12 24 43 PM

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 23
        compileSdkVersion = 31
        targetSdkVersion = 31
        ndkVersion = "21.4.7075529"
    }

Switching to JDK11, if done correctly will solve the problem. This is definitely not a module bug. Carefully examine whether JDK11 is actually in use in the build, versus just that you think it is in use. I’ve already worked with a few people who thought they were using JDK11 but in fact they were not because of some obscure setting or a different way of executing gradle.

The compiler bug in play is intermittent. If this module doesn’t trigger it, some other module will eventually.

For Anybody Still looking for solutions in 2024 try this out, Add org.gradle.java.home=path of your jdk like this: image

It specifies the Java home directory that Gradle should use when executing Java-related tasks, such as compiling Java code or running Java applications.

stackoverflow: https://stackoverflow.com/questions/18487406/how-do-i-tell-gradle-to-use-specific-jdk-version

Alright so I inited a fresh new project, manually updated everything to jdk11, added few libs before react-native-device-info and I’m still getting the same error as original post package.json

  "dependencies": {
    "@sentry/react-native": "^3.2.3",
    "promise": "^8.0.3",
    "react": "17.0.2",
    "react-native": "0.66.3",
    "react-native-bootsplash": "^4.0.1",
    "react-native-contacts": "^7.0.2",
    "react-native-country-picker-modal": "^2.0.0",
    "react-native-device-info": "^8.4.8",
    "react-native-flipper": "^0.121.1"
  },
> npx react-native info   
info Fetching system and libraries information...
System:
    OS: macOS 12.0.1
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
    Memory: 27.88 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.2.0 - ~/.asdf/installs/nodejs/16.2.0/bin/node
    Yarn: 1.22.10 - ~/.asdf/shims/yarn
    npm: 7.13.0 - ~/.asdf/installs/nodejs/16.2.0/bin/npm
    Watchman: 2021.11.15.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
    Android SDK:
      API Levels: 29, 30, 31
      Build Tools: 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0
      System Images: android-29 | Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7784292
    Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.12 - /usr/local/opt/openjdk@11/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.66.3 => 0.66.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

and then in Android Studio: Screen Shot 2021-11-25 at 12 24 43 PM android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 23
        compileSdkVersion = 31
        targetSdkVersion = 31
        ndkVersion = "21.4.7075529"
    }

I am getting the same issue. And I now just remove this dependecy and the app is successfully build. I am not sure whether it is JDK8 issue, but switching to JDK11 not solving the problem.

For whoever not being able to find the location for gradle settings File --> Structure --> SDK Location --> JDK Location was moved to Gradle Settings