I am the maintainer of the react-native-webview-leaflet package. The package properly displays a leaflet map in a React Native WebView during development. However, when the application is built for Android using the expo build:android
command, following error is displayed indicating the WebView doesn’t know how to handle this type of file because it is being labeled as an asset
.
The successful development tests required me to import the HTML file like this:
require("./assets/dist/index.html")
This method of importing the file resulted in the error shown above.
I found this GitHub issue here : https://github.com/facebook/react-native/issues/16133 . One of the comments in that issue mentions that Android expects to receive a File
url type that is used by the WebView’s source property as a uri like this:
source={Platform.OS === 'ios' ? require('./index.html') : {uri: "file:///android_asset/index.html"}}
Unfortunately, following this technique doesn’t even work in development, and results in the following error indicating the file was not found:
Finally, my app.json includes the following modifications to assetBundlePatterns
, and packagerOpts
"assetBundlePatterns": [
"**/*",
"assets/**"],
"packagerOpts": {
"projectRoots": "",
"config": "rn-cli.config.js",
"assetExts": ["html"]
},
Is it possible to get a production app to recognize and execute the asset
source file?