[英]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.