反应本机Web视图错误,com.reactnativecommunity.webview.events不存在

时间:2019-06-12 11:07:59

标签: react-native android-webview

我正在尝试使用https://github.com/react-native-community/react-native-webview

当我尝试react-native run-android时有任何想法,如何使用Webview会出现此错误?

\ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:54:错误:包com.reactnativecommunity.webview.events不存在

使用:

react-native-cli:2.0.1 反应本机:0.57.1​​

完整错误:

  

任务:react-native-webview:compileDebugJavaWithJavac   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:54:错误:包com.reactnativecommunity.webview.events确实不存在   导入com.reactnativecommunity.webview.events.TopLoadingErrorEvent;                                                 ^   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:55:错误:包com.reactnativecommunity.webview.events确实不存在   导入com.reactnativecommunity.webview.events.TopLoadingFinishEvent;                                                 ^   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:56:错误:包com.reactnativecommunity.webview.events确实不存在   导入com.reactnativecommunity.webview.events.TopLoadingProgressEvent;                                                 ^   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:57:错误:包com.reactnativecommunity.webview.events确实不存在   导入com.reactnativecommunity.webview.events.TopLoadingStartEvent;                                                 ^   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:58:错误:包com.reactnativecommunity.webview.events确实不存在   导入com.reactnativecommunity.webview.events.TopMessageEvent;                                                 ^   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:59:错误:包com.reactnativecommunity.webview.events确实不存在   导入com.reactnativecommunity.webview.events.TopShouldStartLoadWithRequestEvent;                                                 ^   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:455:错误:找不到符号       export.put(TopLoadingProgressEvent.EVENT_NAME,MapBuilder.of(“ registrationName”,“ onLoadingProgress”)));                  ^     符号:变量TopLoadingProgressEvent     位置:类RNCWebViewManager   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:456:错误:找不到符号       export.put(TopShouldStartLoadWithRequestEvent.EVENT_NAME,MapBuilder.of(“ registrationName”,“ onShouldStartLoadWithRequest”)));                  ^     符号:变量TopShouldStartLoadWithRequestEvent     位置:类RNCWebViewManager   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:457:错误:枚举ScrollEventType中的方法getJSEventName无法应用于给定类型;       export.put(ScrollEventType.getJSEventName(ScrollEventType.SCROLL),MapBuilder.of(“ registrationName”,“ onScroll”)));                                 ^     必需:无参数     找到:ScrollEventType     原因:实际和正式论点清单的长度不同   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:732:错误:找不到符号           新的TopLoadingProgressEvent(               ^     符号:类TopLoadingProgressEvent     位置:类RNCWebChromeClient   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:617:错误:找不到符号           新的TopLoadingStartEvent(               ^     符号:类TopLoadingStartEvent     位置:类RNCWebViewClient   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:626:错误:找不到符号           新的TopShouldStartLoadWithRequestEvent(               ^     符号:类TopShouldStartLoadWithRequestEvent     位置:类RNCWebViewClient   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:659:错误:找不到符号           新的TopLoadingErrorEvent(webView.getId(),eventData));               ^     符号:类TopLoadingErrorEvent     位置:类RNCWebViewClient   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:665:错误:找不到符号           新的TopLoadingFinishEvent(               ^     符号:类TopLoadingFinishEvent     位置:类RNCWebViewClient   C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java:901:错误:找不到符号         dispatchEvent(this,new TopMessageEvent(this.getId(),message));                                 ^     符号:类TopMessageEvent     位置:类RNCWebView   注意:C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java使用或覆盖已弃用的API。   注意:有关详细信息,请使用-Xlint:deprecation重新编译。   注意:C:\ Users \ Matt \ sites \ tcapp \ node_modules \ react-native-webview \ android \ src \ main \ java \ com \ reactnativecommunity \ webview \ RNCWebViewManager.java使用未经检查或不安全的操作。   注意:使用-Xlint:unchecked重新编译以获取详细信息。   15个错误

     

任务:react-native-webview:compileDebugJavaWithJavac FAILED

2 个答案:

答案 0 :(得分:1)

仅供参考-相关更改是将其添加到您的./android/gradle.properties文件中:

android.useAndroidX=true
android.enableJetifier=true

Check here

答案 1 :(得分:0)

这个问题发生在我身上

我有这些版本的react-native和react-native-webview版本

 "react-native-webview": "^5.12.1"

{
   "react": "16.8.3",
   "react-native": "0.59.9",
   "react-native-webview": "^5.12.1",
   ...
}

对于我以前的项目版本,一切都很好,这个版本没有任何问题。

在更新了android-studio并升级了gradle之后,我重新构建并运行了相同的项目(在我从github存储库中克隆了相同的项目之后)。发生此问题,然后我放置并检查了react-native-webview的每个新版本(5.12.1以上)。最终,它匹配并解决了错误,并成功使用此版本构建了应用程序。

"react-native-webview": "^7.5.2"

{
   "react": "16.8.3",
   "react-native": "0.59.9",
   "react-native-webview": "^7.5.2",
   ...
}