无法在我的项目中运行 react-native-maps
Posted
技术标签:
【中文标题】无法在我的项目中运行 react-native-maps【英文标题】:Can't able to run react-native-maps in my Project 【发布时间】:2019-04-01 10:27:07 【问题描述】:我正在尝试在我的项目中安装 react-native-maps,并按照https://github.com/react-native-community/react-native-maps/blob/master/docs/installation.md 中给出的说明进行操作。但是在 android 中运行我的项目后仍然出现错误,它显示 UIBlock 的错误,该错误出现在 Android Studio 中 react-native-maps 的 AirMapModule.java 中。有人可以帮我解决这个问题吗?
这是我的项目的版本:
"react": "16.6.1",
"react-native": "^0.59.2",
"react-native-maps": "^0.23.0"
这是我得到的错误:
^
symbol: class UIBlock
location: package com.facebook.react.uimanager
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:129: error: getCurrentActivity() is not public in ReactContext; cannot be accessed from outside package
if (!contextHasBug(appContext.getCurrentActivity()))
^
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:130: error: getCurrentActivity() is not public in ReactContext; cannot be accessed from outside package
superContext = appContext.getCurrentActivity();
^
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:133: error: cannot find symbol
if (!contextHasBug(reactContext.getCurrentActivity()))
^
symbol: method getCurrentActivity()
location: variable reactContext of type ThemedReactContext
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapView.java:134: error: cannot find symbol
superContext = reactContext.getCurrentActivity();
^
symbol: method getCurrentActivity()
location: variable reactContext of type ThemedReactContext
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\ViewAttacherGroup.java:23: error: cannot find symbol
this.setOverflow("hidden"); // Change to ViewProps.HIDDEN until RN 0.57 is base
^
symbol: method setOverflow(String)
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapMarkerManager.java:127: error: method does not override or implement a method from a supertype
@Override
^
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapMarkerManager.java:130: error: cannot find symbol
super.setZIndex(view, zIndex);
^
symbol: method setZIndex(AirMapMarker,float)
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapModule.java:90: error: cannot find symbol
uiManager.addUIBlock(new UIBlock()
^
symbol: class UIBlock
location: class AirMapModule
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapModule.java:149: error: cannot find symbol
uiManager.addUIBlock(new UIBlock()
^
symbol: class UIBlock
location: class AirMapModule
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapModule.java:192: error: cannot find symbol
uiManager.addUIBlock(new UIBlock()
^
symbol: class UIBlock
location: class AirMapModule
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapModule.java:229: error: cannot find symbol
uiManager.addUIBlock(new UIBlock()
^
symbol: class UIBlock
location: class AirMapModule
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\AirMapModule.java:262: error: cannot find symbol
uiManager.addUIBlock(new UIBlock()
^
symbol: class UIBlock
location: class AirMapModule
D:\Maps\Project\node_modules\react-native-maps\lib\android\src\main\java\com\airbnb\android\react\maps\RegionChangeEvent.java:15: error: no suitable constructor found for Event(int)
super(id);
^
constructor Event.Event() is not applicable
(actual and formal argument lists differ in length)
constructor Event.Event(int,long) is not applicable
(actual and formal argument lists differ in length)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
14 errors```
【问题讨论】:
你能显示代码sn-p或例子吗? 实际上,问题不在代码中,由于上述GitHub链接中的说明中定义的Android Studio中的react-native-maps手动链接,我得到了错误。这个错误可能是由于 React-Native 的当前版本,即 0.59.2,我也检查了github.com/react-native-community/react-native-maps/issues/2762,但我不确定这个错误是否是由于这个原因造成的。您在自己的项目中安装 react-native-maps 时是否遇到任何错误? 不,我没有遇到任何问题 【参考方案1】:尝试按照此处的说明拆分您的 Maven 依赖项:
allprojects
repositories
mavenLocal()
jcenter()
maven
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
maven
url "https://maven.google.com"
https://github.com/react-native-community/react-native-maps/issues/2090
【讨论】:
感谢您的帮助,我只是想知道您在哪个版本的 React Native 和 React 中安装了 react-native-maps?以上是关于无法在我的项目中运行 react-native-maps的主要内容,如果未能解决你的问题,请参考以下文章
无法使用 Xcode 7.3.1 在我的 Swift 2 项目中检查带有“po”的变量 - 加载辅助函数时出错