Naoto Ida Naoto Ida - 1 year ago 198
Android Question

Load JS/CSS from bundle package with React Native for Android

I've seen many solutions for loading JS/CSS from a bundle package with a React Native app targeted towards iOS like this, but not for Android.

My webview code is like this:

source={{html: html, baseUrl: `file:///android_asset/web`}}

variable is like this:

const html = `
<link rel="stylesheet" type="text/css" href="styles.css" />
<p class="someText">Foo</p>

My project directories look like this:

-> assets
-> web
-> styles.css

If anyone has solutions for this it would be awesome.

Answer Source

Place the styles.css in the following path:


Then, set the baseURL of the <WebView> to the following:

<WebView source={{html: html, baseUrl: 'file:///android_asset/'}} />

P.S: You have to execute react-native run-android every time you made changes to the styling.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download