如何在Android中捆绑React Native的图像资源?

如何在Android中捆绑React Native的图像资源?

问题描述:

我使用

react-native bundle --entry-file "index.android.js" --platform "android" --bundle-output "./assets/index.android.bundle" --verbose

to打包JS代码包并将其放入资源,它可以工作但本地图像资源无法显示,本地图像资源位于 ./ App / Img / 文件夹中,并用于:

to package the JS code bundle and put it into assets, it works but the local Image resources can't be displayed, the local image resources located in ./App/Img/ folder, and be used in:

const icon1 = require('./App/Img/slider.png');

我如何捆绑这些资源文件,以便生成一个正在运行的apk。

How can I bundle this resource files too so that I can generate a single running apk.

我使用 bundle 命令将资源捆绑到android res /文件夹中:

I use the bundle command to bundle resources into android res/ folder:

    echo "START bundle for android normal resources release"
    react-native bundle \
    --platform android \
    --entry-file index.android.js \
    --bundle-output android/app/src/main/assets/index.android.bundle \
    --assets-dest  android/app/src/main/res/ \
    --dev false

然后用gradlew构建:

then build with gradlew:

./gradlew installRelease