react-native-webview 在调用时崩溃应用程序
react-native-webview crashes application when invoked
我正在使用 react-native-webview 库加载网页,它在调试时工作正常,但是当我创建发布版本时。并单击选项卡加载 webview ,应用程序崩溃。以下是错误。我最后也附上了错误跟踪。
我正在使用
本机反应:“0.62.0”
react-native-webview : "^9.0.2",
这是我点击按钮加载 webview 屏幕时的轨迹。
> 2020-04-10 11:39:44.812 2584-2646/com.trackplayer E/ReactNativeJS:
> Error: crypto.getRandomValues() not supported. See
> https://github.com/uuidjs/uuid#getrandomvalues-not-supported
>
> This error is located at:
> in n
> in RCTView
> in y
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in S
> in RCTView
> in RCTView
> in E
> in RCTView
> in c
> in RCTView
> in Unknown
> in v
> in Unknown
> in w
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in RCTView
> in RCTView
> in RCTView
> in k
> in ForwardRef
> in PanGestureHandler
> in RCTView
> in k
> in ForwardRef
> in RCTView
> in D
> in Unknown
> in RCTView
> in C
> in RCTView
> in H
> in S
> in h
> in RNCSafeAreaView
> in Unknown
> in Unknown
> in GestureHandlerRootView
> in Unknown
> in b
> in Unknown
> in O
> in Unknown
> in ForwardRef
> in Unknown
> in ForwardRef
> in S
> in RCTView
> in RCTView
> in E 2020-04-10 11:39:44.818 2584-2646/com.trackplayer E/ReactNativeJS: Error: crypto.getRandomValues() not supported. See
> https://github.com/uuidjs/uuid#getrandomvalues-not-supported
>
> This error is located at:
> in n
> in RCTView
> in y
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in S
> in RCTView
> in RCTView
> in E
> in RCTView
> in c
> in RCTView
> in Unknown
> in v
> in Unknown
> in w
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in RCTView
> in RCTView
> in RCTView
> in k
> in ForwardRef
> in PanGestureHandler
> in RCTView
> in k
> in ForwardRef
> in RCTView
> in D
> in Unknown
> in RCTView
> in C
> in RCTView
> in H
> in S
> in h
> in RNCSafeAreaView
> in Unknown
> in Unknown
> in GestureHandlerRootView
> in Unknown
> in b
> in Unknown
> in O
> in Unknown
> in ForwardRef
> in Unknown
> in ForwardRef
> in S
> in RCTView
> in RCTView
> in E 2020-04-10 11:39:44.822 2584-2647/com.trackplayer E/unknown:ReactNative: Error: crypto.getRandomValues() not supported.
> See https://github.com/uuidjs/uuid#getrandomvalues-not-supported
>
> This error is located at:
> in n
> in RCTView
> in y
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in S
> in RCTView
> in RCTView
> in E
> in RCTView
> in c
> in RCTView
> in Unknown
> in v
> in Unknown
> in w
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in RCTView
> in RCTView
> in RCTView
> in k
> in ForwardRef
> in PanGestureHandler
> in RCTView
> in k
> in ForwardRef
> in RCTView
> in D
> in Unknown
> in RCTView
> in C
> in RCTView
> in H
> in S
> in h
> in RNCSafeAreaView
> in Unknown
> in Unknown
> in GestureHandlerRootView
> in Unknown
> in b
> in Unknown
> in O
> in Unknown
> in ForwardRef
> in Unknown
> in ForwardRef
> in S
> in RCTView
> in RCTView
> in E, stack:
> default@717:132
> f@722:329
> n@714:2621
> Bn@92:31529
> ui@92:49357
> ja@92:72034
> Oa@92:71959
> Ia@92:69253
> Ia@-1
> <unknown>@92:25480
> unstable_runWithPriority@183:3503
> dn@92:25427
> fn@92:25362
> Pe@92:90879
> Re@92:13478
> Ie@92:13664
> receiveTouches@92:14448
> value@27:3544
> <unknown>@27:840
> value@27:2798
> value@27:812
> value@-1 2020-04-10 11:39:44.831 2584-2647/com.trackplayer E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
> Process: com.trackplayer, PID: 2584
> com.facebook.react.common.JavascriptException: Error: crypto.getRandomValues() not supported. See
> https://github.com/uuidjs/uuid#getrandomvalues-not-supported
>
> This error is located at:
> in n
> in RCTView
> in y
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in S
> in RCTView
> in RCTView
> in E
> in RCTView
> in c
> in RCTView
> in Unknown
> in v
> in Unknown
> in w
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in RCTView
> in RCTView
> in RCTView
> in k
> in ForwardRef
> in PanGestureHandler
> in RCTView
> in k
> in ForwardRef
> in RCTView
> in D
> in Unknown
> in RCTView
> in C
> in RCTView
> in H
> in S
> in h
> in RNCSafeAreaView
> in Unknown
> in Unknown
> in GestureHandlerRootView
> in Unknown
> in b
> in Unknown
> in O
> in Unknown
> in ForwardRef
> in Unknown
> in ForwardRef
> in S
> in RCTView
> in RCTView
> in E, stack:
> default@717:132
> f@722:329
> n@714:2621
> Bn@92:31529
> ui@92:49357
> ja@92:72034
> Oa@92:71959
> Ia@92:69253
> Ia@-1
> <unknown>@92:25480
> unstable_runWithPriority@183:3503
> dn@92:25427
> fn@92:25362
> Pe@92:90879
> Re@92:13478
> Ie@92:13664
> receiveTouches@92:14448
> value@27:3544
> <unknown>@27:840
> value@27:2798
> value@27:812
> value@-1
>
> at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:79)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
> at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
> at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
> at android.os.Handler.handleCallback(Handler.java:883)
> at android.os.Handler.dispatchMessage(Handler.java:100)
> at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
> at android.os.Looper.loop(Looper.java:214)
> at com.facebook.react.bridge.queue.MessageQueueThreadImpl.run(MessageQueueThreadImpl.java:226)
> at java.lang.Thread.run(Thread.java:919) 2020-04-10 11:39:44.850 2584-2647/com.trackplayer I/Process: Sending signal. PID:
> 2584 SIG: 9
这对我有用。我刚用过。
expo install react-native-webview
"react-native-webview": "8.1.1"
import { WebView } from 'react-native-webview'
<WebView source={{ uri: 'https://expo.io' }} style={{ marginTop: 20, height: 500 }} />
react-native-webview升级到9.1.3版本后出现同样的错误。
降级到 9.1.1 后错误消失。版本 9.1.2 未选中。
2020.04.12更新。
在版本 9.1.4 中也存在该错误。如下所述,使用 'react-native-get-random-values' 所有作品。我正在使用 CLI 版本。
2020.04.24更新。
在版本 9.2.2 中,该错误已得到纠正。
我删除了包 'react-native-get-random-values' 并且一切正常。
似乎是新版本的错误,但根据此文档 (https://github.com/react-native-community/react-native-webview/issues/1312) 可以按如下方式解决
首先安装 react-native-get-random-values,然后将其导入文件顶部
import 'react-native-get-random-values';
import React, { Component } from 'react';
import { WebView } from 'react-native-webview';
import {
StyleSheet,
View,
Text,
} from 'react-native';
export default class MyWeb extends Component {
render() {
return (
<View style={{ backgroundColor: 'blue',flex: 1 }}>
<WebView
source={{ uri: 'https://url.ngrok.io' }}
style={{ marginTop: 20, }}
/>
</View>
);
}
}
安装 'react-native-get-random-values' 包。
然后在你的react native app的入口文件添加"import 'react-native-get-random-values'"如下。就像 index.js 当应用程序使用 React Native CLI 创建时
import 'react-native-get-random-values';
import React, {Component} from 'react';
import { WebView } from 'react-native-webview';
class MyWebComponent extends Component {
render() {
return <WebView source={{ uri: 'https://reactnative.dev/' }} />;
}
}
安装 react-native-get-random-values 包..之后,尝试将导入移动到文件的最顶部..
index.js
这种方式对我有用..
import 'react-native-get-random-values';
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
为我解决了这个问题:
`react-native-webview:“8.0.4”,
将 属性 androidHardwareAccelerationDisabled={true} 添加到 webview
<WebView
source={{ uri: 'https://reatnative.com' }}
androidHardwareAccelerationDisabled={true}
/>
我正在使用 react-native-webview 库加载网页,它在调试时工作正常,但是当我创建发布版本时。并单击选项卡加载 webview ,应用程序崩溃。以下是错误。我最后也附上了错误跟踪。
我正在使用 本机反应:“0.62.0” react-native-webview : "^9.0.2",
这是我点击按钮加载 webview 屏幕时的轨迹。
> 2020-04-10 11:39:44.812 2584-2646/com.trackplayer E/ReactNativeJS:
> Error: crypto.getRandomValues() not supported. See
> https://github.com/uuidjs/uuid#getrandomvalues-not-supported
>
> This error is located at:
> in n
> in RCTView
> in y
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in S
> in RCTView
> in RCTView
> in E
> in RCTView
> in c
> in RCTView
> in Unknown
> in v
> in Unknown
> in w
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in RCTView
> in RCTView
> in RCTView
> in k
> in ForwardRef
> in PanGestureHandler
> in RCTView
> in k
> in ForwardRef
> in RCTView
> in D
> in Unknown
> in RCTView
> in C
> in RCTView
> in H
> in S
> in h
> in RNCSafeAreaView
> in Unknown
> in Unknown
> in GestureHandlerRootView
> in Unknown
> in b
> in Unknown
> in O
> in Unknown
> in ForwardRef
> in Unknown
> in ForwardRef
> in S
> in RCTView
> in RCTView
> in E 2020-04-10 11:39:44.818 2584-2646/com.trackplayer E/ReactNativeJS: Error: crypto.getRandomValues() not supported. See
> https://github.com/uuidjs/uuid#getrandomvalues-not-supported
>
> This error is located at:
> in n
> in RCTView
> in y
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in S
> in RCTView
> in RCTView
> in E
> in RCTView
> in c
> in RCTView
> in Unknown
> in v
> in Unknown
> in w
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in RCTView
> in RCTView
> in RCTView
> in k
> in ForwardRef
> in PanGestureHandler
> in RCTView
> in k
> in ForwardRef
> in RCTView
> in D
> in Unknown
> in RCTView
> in C
> in RCTView
> in H
> in S
> in h
> in RNCSafeAreaView
> in Unknown
> in Unknown
> in GestureHandlerRootView
> in Unknown
> in b
> in Unknown
> in O
> in Unknown
> in ForwardRef
> in Unknown
> in ForwardRef
> in S
> in RCTView
> in RCTView
> in E 2020-04-10 11:39:44.822 2584-2647/com.trackplayer E/unknown:ReactNative: Error: crypto.getRandomValues() not supported.
> See https://github.com/uuidjs/uuid#getrandomvalues-not-supported
>
> This error is located at:
> in n
> in RCTView
> in y
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in S
> in RCTView
> in RCTView
> in E
> in RCTView
> in c
> in RCTView
> in Unknown
> in v
> in Unknown
> in w
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in RCTView
> in RCTView
> in RCTView
> in k
> in ForwardRef
> in PanGestureHandler
> in RCTView
> in k
> in ForwardRef
> in RCTView
> in D
> in Unknown
> in RCTView
> in C
> in RCTView
> in H
> in S
> in h
> in RNCSafeAreaView
> in Unknown
> in Unknown
> in GestureHandlerRootView
> in Unknown
> in b
> in Unknown
> in O
> in Unknown
> in ForwardRef
> in Unknown
> in ForwardRef
> in S
> in RCTView
> in RCTView
> in E, stack:
> default@717:132
> f@722:329
> n@714:2621
> Bn@92:31529
> ui@92:49357
> ja@92:72034
> Oa@92:71959
> Ia@92:69253
> Ia@-1
> <unknown>@92:25480
> unstable_runWithPriority@183:3503
> dn@92:25427
> fn@92:25362
> Pe@92:90879
> Re@92:13478
> Ie@92:13664
> receiveTouches@92:14448
> value@27:3544
> <unknown>@27:840
> value@27:2798
> value@27:812
> value@-1 2020-04-10 11:39:44.831 2584-2647/com.trackplayer E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
> Process: com.trackplayer, PID: 2584
> com.facebook.react.common.JavascriptException: Error: crypto.getRandomValues() not supported. See
> https://github.com/uuidjs/uuid#getrandomvalues-not-supported
>
> This error is located at:
> in n
> in RCTView
> in y
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in S
> in RCTView
> in RCTView
> in E
> in RCTView
> in c
> in RCTView
> in Unknown
> in v
> in Unknown
> in w
> in Unknown
> in Unknown
> in Unknown
> in Unknown
> in RCTView
> in RCTView
> in RCTView
> in RCTView
> in k
> in ForwardRef
> in PanGestureHandler
> in RCTView
> in k
> in ForwardRef
> in RCTView
> in D
> in Unknown
> in RCTView
> in C
> in RCTView
> in H
> in S
> in h
> in RNCSafeAreaView
> in Unknown
> in Unknown
> in GestureHandlerRootView
> in Unknown
> in b
> in Unknown
> in O
> in Unknown
> in ForwardRef
> in Unknown
> in ForwardRef
> in S
> in RCTView
> in RCTView
> in E, stack:
> default@717:132
> f@722:329
> n@714:2621
> Bn@92:31529
> ui@92:49357
> ja@92:72034
> Oa@92:71959
> Ia@92:69253
> Ia@-1
> <unknown>@92:25480
> unstable_runWithPriority@183:3503
> dn@92:25427
> fn@92:25362
> Pe@92:90879
> Re@92:13478
> Ie@92:13664
> receiveTouches@92:14448
> value@27:3544
> <unknown>@27:840
> value@27:2798
> value@27:812
> value@-1
>
> at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:79)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
> at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
> at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
> at android.os.Handler.handleCallback(Handler.java:883)
> at android.os.Handler.dispatchMessage(Handler.java:100)
> at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
> at android.os.Looper.loop(Looper.java:214)
> at com.facebook.react.bridge.queue.MessageQueueThreadImpl.run(MessageQueueThreadImpl.java:226)
> at java.lang.Thread.run(Thread.java:919) 2020-04-10 11:39:44.850 2584-2647/com.trackplayer I/Process: Sending signal. PID:
> 2584 SIG: 9
这对我有用。我刚用过。
expo install react-native-webview
"react-native-webview": "8.1.1"
import { WebView } from 'react-native-webview'
<WebView source={{ uri: 'https://expo.io' }} style={{ marginTop: 20, height: 500 }} />
react-native-webview升级到9.1.3版本后出现同样的错误。 降级到 9.1.1 后错误消失。版本 9.1.2 未选中。
2020.04.12更新。 在版本 9.1.4 中也存在该错误。如下所述,使用 'react-native-get-random-values' 所有作品。我正在使用 CLI 版本。
2020.04.24更新。 在版本 9.2.2 中,该错误已得到纠正。 我删除了包 'react-native-get-random-values' 并且一切正常。
似乎是新版本的错误,但根据此文档 (https://github.com/react-native-community/react-native-webview/issues/1312) 可以按如下方式解决
首先安装 react-native-get-random-values,然后将其导入文件顶部
import 'react-native-get-random-values';
import React, { Component } from 'react';
import { WebView } from 'react-native-webview';
import {
StyleSheet,
View,
Text,
} from 'react-native';
export default class MyWeb extends Component {
render() {
return (
<View style={{ backgroundColor: 'blue',flex: 1 }}>
<WebView
source={{ uri: 'https://url.ngrok.io' }}
style={{ marginTop: 20, }}
/>
</View>
);
}
}
安装 'react-native-get-random-values' 包。
然后在你的react native app的入口文件添加"import 'react-native-get-random-values'"如下。就像 index.js 当应用程序使用 React Native CLI 创建时
import 'react-native-get-random-values';
import React, {Component} from 'react';
import { WebView } from 'react-native-webview';
class MyWebComponent extends Component {
render() {
return <WebView source={{ uri: 'https://reactnative.dev/' }} />;
}
}
安装 react-native-get-random-values 包..之后,尝试将导入移动到文件的最顶部..
index.js
这种方式对我有用..
import 'react-native-get-random-values';
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
为我解决了这个问题: `react-native-webview:“8.0.4”,
将 属性 androidHardwareAccelerationDisabled={true} 添加到 webview
<WebView
source={{ uri: 'https://reatnative.com' }}
androidHardwareAccelerationDisabled={true}
/>