React Native Android:静态图像未在生产发布的 apk 中显示
React Native Android: Static Image is not showing in production released apk
我的反应本机应用程序中有静态图像通过
访问
<Image source={require("../assets/preview-full-img-title-logo@2x.png")} />
在开发中它显示良好但在生产版本中 APK 不显示可能是什么原因?我已按照此处提到的步骤进行操作。
https://facebook.github.io/react-native/docs/signed-apk-android.html
这是为我执行的命令:
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/
验证图像是否在 ../res
文件夹中 ${project}/android/app/src/res
。如果没有,那么您需要复制该文件夹中的图像。这可以使用以下反应命令完成
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/
理想情况下,当图像尺寸较大时,Android 会发生这种情况。在运行时避免此类问题的另一种方法是优化图像大小。
我正在使用具有 shrinkResources true
配置的 react-native v0.59.9。
这使得 react-native 找不到资产。
请确保您没有在 android build.gradle 上设置 shrinkResources
除非 react-native 的新版本稍后支持它。
我正在使用 RN 0.61.2
如@made-in-moon 所说,这对我有用:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
对于iOS14也可以升级到react-native最新版本0.63.3
检查图像文件的名称或尝试renaming.In我的情况,它是图像的名称。我重命名(删除了“-”字符)图像并且它起作用了。
我的反应本机应用程序中有静态图像通过
访问 <Image source={require("../assets/preview-full-img-title-logo@2x.png")} />
在开发中它显示良好但在生产版本中 APK 不显示可能是什么原因?我已按照此处提到的步骤进行操作。
https://facebook.github.io/react-native/docs/signed-apk-android.html
这是为我执行的命令:
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/
验证图像是否在 ../res
文件夹中 ${project}/android/app/src/res
。如果没有,那么您需要复制该文件夹中的图像。这可以使用以下反应命令完成
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/
理想情况下,当图像尺寸较大时,Android 会发生这种情况。在运行时避免此类问题的另一种方法是优化图像大小。
我正在使用具有 shrinkResources true
配置的 react-native v0.59.9。
这使得 react-native 找不到资产。
请确保您没有在 android build.gradle 上设置 shrinkResources
除非 react-native 的新版本稍后支持它。
我正在使用 RN 0.61.2
如@made-in-moon 所说,这对我有用:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
对于iOS14也可以升级到react-native最新版本0.63.3
检查图像文件的名称或尝试renaming.In我的情况,它是图像的名称。我重命名(删除了“-”字符)图像并且它起作用了。