任何人的成功使用局部图像中的反应原生Android的? [英] Anyone success in using local image in react native for Android?
问题描述
我使用的是原生的反应0.14.2。我问在 github上这个问题,但回购是压倒性的通过太多的问题。希望我可以在这里找到答案。
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
这里的code来显示图像:
Here's the code to show the image:
<Image
source={require('./reactnative/assets/image.png')}
resizeMode='contain'
style={styles.image} />
在与本地主机一起运行上面的code正常工作反应母语启动
。不过,这并不捆绑后反应本土的资源投入到APK工作:
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/
下面是输出:
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
这是不是正确的方式来生成APK与原生的反应?请排查。谢谢!
Is it the right way to generate the apk with react native? Please troubleshoot. Thanks!
推荐答案
您可能要访问<一href="https://facebook.github.io/react-native/docs/image.html#adding-static-resources-to-your-android-app" rel="nofollow">https://facebook.github.io/react-native/docs/image.html#adding-static-resources-to-your-android-app为您查询,基本上您设置code像
&lt;图像源= {要求(./ RES / check.png')} /&GT;
使用JS文件,并把你的图片在绘制文件夹中,例如检查。 PNG在安卓/ APP / src目录/主/ RES /绘制,华电国际
you might want to look visit https://facebook.github.io/react-native/docs/image.html#adding-static-resources-to-your-android-app for you query, basically you set up you code like
<Image source={require('./ res/check.png')} />
using the JS files and putting your images in the drawable folders e.g check.png in android/app/src/main/res/drawable-hdpi
这篇关于任何人的成功使用局部图像中的反应原生Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!