3

I'm getting the following error when I try to build the project using $ react-native run-android.

> Task :react-native-device-info:compileDebugJavaWithJavac FAILED
/Users/user/Desktop/mobile/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java:31: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
                                 ^
/Users/user/Desktop/mobile/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java:838: error: cannot find symbol
                         @Nullable Object data) {
                          ^
  symbol:   class Nullable
  location: class RNDeviceModule
Note: /Users/ammiel/Desktop/mobile/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

FAILURE: Build failed with an exception.
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-device-info:compileReleaseJavaWithJavac'.

> Compilation failed; see the compiler error output for details.

I have jetify running postinstall and have

android.useAndroidX=true
android.enableJetifier=true

in my gradle.properties.

Been lurking at many pages/github pages with no success :/ Any help is appreciated!

Other info:

react-native: 0.59.10

react-native-device-info: 5.6.1

2 Answers2

0

I faced the same problem like you!

But I managed to solve it by just adding the dependencies.

yarn add react-native-device-info

Wolla! The app is now running.

Teo
  • 876
  • 9
  • 22
0

for that problem, one way is that you can update the new `react-native-device-

info` to solve the problem.

it releases note give the version which support androidx

2.3.0 feat: AndroidX support (backwards/forwards compatible) (https://github.com/react-native-community/react-native-device-info/pull/733) fix: isTablet() Android using Google-recommended / robust style (https://github.com/react-native-community/react-native-device-info/pull/730)

the second way is to change the code manually.

the reason is that the android studio does not translate it to androidX API, so it reports errors. so you have to replace them manually or use the newest the version which had changed to android.

Besides them, you can see this question, it may help you

Lenoarod
  • 3,441
  • 14
  • 25