简体   繁体   English

反应本机 android 未使用 react-native-device-info 编译

[英]React native android not compiling with react-native-device-info

I'm getting the following error when I try to build the project using $ react-native run-android .当我尝试使用$ 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我已经 jetify 运行 postinstall 并且有

android.useAndroidX=true
android.enableJetifier=true

in my gradle.properties.在我的 gradle.properties 中。

Been lurking at many pages/github pages with no success:/ Any help is appreciated!潜伏在许多页面/ github页面但没有成功:/任何帮助表示赞赏!

Other info:其他信息:

react-native: 0.59.10 react-native:0.59.10

react-native-device-info: 5.6.1反应本机设备信息:5.6.1

In my case, i have used compileSdkVersion 28.就我而言,我使用了 compileSdkVersion 28。

buildToolsVersion = "28.0.3"
minSdkVersion = 21
compileSdkVersion = 28
targetSdkVersion = 28

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.该应用程序现在正在运行。

for that problem, one way is that you can update the new `react-native-device-对于这个问题,一种方法是您可以更新新的 `react-native-device-

info` to solve the problem. info`来解决问题。

it releases note give the version which support androidx它发布注释给出了支持 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 ) 2.3.0 壮举:AndroidX 支持(向后/向前兼容)( https://github.com/react-native-community/react-native-device-info/pull/733 )修复:isTablet() Android 使用 Google 推荐/ 健壮的风格( 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.原因是android studio没有翻译成androidX API,所以报错。 so you have to replace them manually or use the newest the version which had changed to android.因此您必须手动更换它们或使用已更改为 android 的最新版本。

Besides them, you can see this question , it may help you除了他们,你可以看到这个问题,它可能对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 react-native-device-info使Android上的应用程序崩溃 - react-native-device-info crash the app on android 安装 react-native-device-info 错误 android 后 - after install react-native-device-info error android 在 react-native-device-info 之后 React Native 代码中断 - React Native code broke after react-native-device-info react-native-device-info 获取 getUniqueID() 不适用于 react native 和 android 中的 expo - react-native-device-info get getUniqueID() not working with react native and expo in android 任务':react-native-device-info:processReleaseResources'的执行失败 - Execution failed for task ':react-native-device-info:processReleaseResources' 未定义不是对象(评估“RNDeviceInfo.deviceId”)-react-native-device-info 中的错误 - undefined is not object (evaluating 'RNDeviceInfo.deviceId') - error in react-native-device-info 清单合并失败。 添加并链接react-native-device-info后 - Manifest merger failed. After adding and linking react-native-device-info 无法使用 react-native-device-info 的 getIPAddress() 返回 IP 地址 - Unable to return IP address using react-native-device-info's getIPAddress() 编译到Android设备时反应本机新构建错误 - React Native fresh build error on compiling to android device React Native - Android 仿真器设备 - React Native - Android Emulator Device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM