Quantcast
Channel: Anyone success in using local image in react native for Android? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Anyone success in using local image in react native for Android?

$
0
0

I'm using react native 0.14.2. I asked this question on github but that repo is overwhelming by too many issues. Hope I can find the answer here.

So here is the project structure:

android-project+---app|   \---src|       \---main|           \---assets|           \---java|           \---res+---reactnative|   \---assets|       \---image@1x.png|       \---image@2x.png|       \---image@3x.png----index.android.js

Here's the code to show the image:

<Image    source={require('./reactnative/assets/image.png')}    resizeMode='contain'    style={styles.image} />

The above code works fine when running together with localhost react-native start. But it doesn't work after bundling react native resources into the apk:

react-native bundle --platform android -dev false --entry-file index.android.js \--bundle-output app/src/main/assets/index.android.bundle \--assets-dest app/src/main/res/

Here's the output:

android-project+---app|   \---src|       \---main|           \---assets|               \---index.android.bundle|           \---java|           \---res|               \---drawable-xxxhdpi|                   \---reactnative_assets_image1.png|               \---drawable-xxhdpi|                   \---reactnative_assets_image1.png|               \---drawable-xhdpi|                   \---reactnative_assets_image1.png|               \---drawable-mdpi|                   \---reactnative_assets_image1.png

Is it the right way to generate the apk with react native? Please troubleshoot. Thanks!


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images