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
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:
…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
init
ed a fresh new project, manually updated everything to jdk11, added few libs beforereact-native-device-info
and I’m still getting the same error as original postpackage.json
and then in Android Studio:
android/build.gradle
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:
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
For whoever not being able to find the location for gradle settings File --> Structure --> SDK Location --> JDK Location was moved to Gradle Settings