varunvs varunvs - 1 year ago 1038
iOS Question

External HTML asset not bundled by React Native in production build for use by Webview

I'm building an Android application using React Native. It has a webview that reads an HTML file locally.

This is the piece of code I'm using to render webview.

<WebView ref="webview"
javaScriptEnabled style={styles.webView} />

This works well during development build. The HTML file loads on the webview and renders well.

But it doesn't on Android release/production build. The webview is empty and if I inspect using chrome://inspect, the webview is empty and doesn't load the HTML file.

From what I understand is the React Native fails to bundle helloworld.html as an asset during Android production build. I noticed that it works fine on iOS.

Any idea how to fix it?

Answer Source

As per the discussions around here, it's a known defect. Assets are not bundled for Android production build but works fine in dev build.

A solution is store assets in Android assets folder manually, and then load the resource using

    source={{ uri: 'file:///android_asset/helloworld.html' }}
    startInLoadingState={true} />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download