React-native :Android 调试构建不会从 react-native 资产文件夹加载图像资产

React-native : Android Debug build does't loads image assets from the react-native assets folder

出于测试和共享目的,我在终端中使用以下代码创建了一个 apk

react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debugScanning

并使用

创建apk
Create debug build:
cd android
./gradlew assembleDebug

以上解决方案来自Whosebug,成功创建了一个好的apk文件,

但是,当我测试 apk 时,它不显示文件夹中的图标

"react-native-project-name/assets" 

只显示白色 space 而不是图标。测试了一些解决方案,但注意解决了这个问题。

版本

react-native-cli: 2.0.1
react-native: 0.55.4

可能有两种情况:

1-检查${project}/android/app/src/ res,如果imgs不在那里,也许你应该在项目根目录手动运行这个命令来复制imgs: react-native bundle --platform android --dev false --entry-file index.android.js \ --bundle-output android/app/src/main/assets/index.android.bundle \ --assets-dest android/app/src/main/res/.

2-问题可能出在图像大小上。我有一个很大的本地 .png 并试图将其调整为一个小缩略图,但它不会显示。 iOS 处理了,Android 没有。

https://github.com/facebook/react-native/issues/9451