'React native webview crashing on Android when attach/selecting a file
I am using react-native-webview v.11 and it works all great unless you try to attach a file using the webview and the Android just crash.
I have been looking everywhere how to solve this, but I couldnt find any resource that could help. Anyone has ever came across this problem and fixed it? Workaround solutions are more than welcome.
Here is my Webview how I use it:
<WebView
style={styles.webView}
containerStyle={resolvedWebViewStyles}
ref={webviewRef}
decelerationRate="normal" // Make scrolling feel native on iOS
source={{uri: reConstructedUri}}
onLoadEnd={handleLoadEnd}
injectedJavaScript={INJECTED_JAVASCRIPT}
onMessage={() => {}}
javaScriptEnabled
/>
I have all the permission required in manifest file as:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Error:
FATAL EXCEPTION: main
Process: fi.hsl.appdev, PID: 15154
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:32 flg=0x1 }} to activity {fi.hsl.appdev/fi.hsl.app.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void com.facebook.react.bridge.Promise.resolve(java.lang.Object)' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:5015)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5056)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Solution 1:[1]
The problem happened in Android 9 or 10 version
for solve it just add androidLayerType={'hardware'}
to WebView
props
<WebView
androidLayerType={'hardware'}
// other props...
/>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Idan |