首页 > 解决方案 > React Native android 不使用 react-native-device-info 编译

问题描述

当我尝试使用$ 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.

我已经 jetify 运行 postinstall 并且有

android.useAndroidX=true
android.enableJetifier=true

在我的 gradle.properties 中。

潜伏在许多页面/ github页面但没有成功:/任何帮助表示赞赏!

其他信息:

反应原生:0.59.10

反应本机设备信息:5.6.1

标签: androidreactjsreact-nativereact-native-device-info

解决方案


我遇到了和你一样的问题!

但我设法通过添加依赖项来解决它。

yarn add react-native-device-info

哇!该应用程序现在正在运行。


推荐阅读