WebView Unable To Access HTML File in Published Application

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:


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": [
    "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?

You could try Asset.fromModule(require(...)) – see these docs for the starting point: https://docs.expo.io/versions/v30.0.0/sdk/asset#expoassetfrommodulemodule

@ide Looks like that did the trick. However, I’m trying to do this as part of a library. Is it correct that using Asset.fromModule will require me to include Expo as a dependency for the library in order to have access to the Asset.fromModule method?

Yes, if you’re using Asset.fromModule in JS you need the expo-asset native code as well.

Can you point me to where the code for Asset is? I’m looking for it in the repo here Expo GitHub, but I can’t find it

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.