How to bundle images resources of React Native in

2019-03-16 18:00发布

问题:

I use

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

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');

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

回答1:

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

then build with gradlew:

./gradlew installRelease