React Native Android编译时与react-native-device-info不兼容。

3
我尝试使用 $ 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并运行了后置安装

android.useAndroidX=true
android.enableJetifier=true

在我的 gradle.properties 文件中。 一直在各个页面/GitHub 页面上潜伏,但都没有成功 :/ 感激任何帮助! 其他信息: react-native: 0.59.10 react-native-device-info: 5.6.1
2个回答

0

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

但是我通过添加依赖项成功解决了它。

yarn add react-native-device-info

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


0
针对这个问题,一种方法是您可以更新新的 `react-native-device-info` 来解决问题。
更新说明中给出支持 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)
第二种方法是手动更改代码。
原因是Android Studio没有将其转换为AndroidX API,因此会报告错误。 因此,您必须手动替换它们或使用最新版本,该版本已更改为Android。
除此之外,您可以看看这个 question ,它可能会对您有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接