【问题标题】:React Native Android: Static Image is not showing in production released apkReact Native Android:静态图像未在生产发布的 apk 中显示
【发布时间】:2016-12-20 20:28:51
【问题描述】:

我的 react-native 应用程序中有静态图像通过访问

  <Image source={require("../assets/preview-full-img-title-logo@2x.png")} />

在开发中显示良好,但在生产版本中 APK 没有显示可能是什么原因?我已按照此处提到的步骤进行操作。

https://facebook.github.io/react-native/docs/signed-apk-android.html

【问题讨论】:

  • 尝试将您的图像源分配给全局变量,例如 var _logo = require(...) 并再试一次。source ={_logo} 即使它不起作用,您也会有更好的实现。
  • 好的,需要专注于解决方案。任何其他建议
  • 您不需要在网址中使用@2x。只需要(“../assets/preview-full-img-title-logo.png”)但不确定这是否与您的问题有关。值得一试:)
  • 不仅这张图片,而且我在应用程序中使用的每张图片,在生产中都没有负载,只是静态图片而不是动态
  • 我遇到了类似的问题,最终在 -Tag 和样式表中分配了“width”和“height”属性。如果没有这个,在某些设备(不是全部)上的生产 apk 中不会绘制图像

标签: reactjs react-native reactjs-flux


【解决方案1】:

这是为我完成的命令:

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/

take a look at github issue>

【讨论】:

  • 它给了我error: option '--bundle-output' missing
  • 从我这里删除两个“\”作品: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/
  • 版本 61.5。此命令创建文件夹并复制图像。但是一旦我关闭终端(并断开电缆)并再次运行应用程序,图像就不再可见。我使用 ... 想法?
  • 您能否再次检查答案中的链接。对吗?
【解决方案2】:

验证图像是否在 ../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 中发生。在运行时避免此类问题的另一种方法是优化图像大小。

【讨论】:

    【解决方案3】:

    我正在使用带有 shrinkResources true 配置的 react-native v0.59.9。 它使 react-native 无法找到资产。

    请确保不要在 android build.gradle 上设置 shrinkResources,除非新版本的 react-native 稍后支持它。

    【讨论】:

      【解决方案4】:

      我正在使用 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/

      【讨论】:

      • 我使用的是 61.5,此命令在我在应用程序中使用的图像内创建了几个文件夹。如果我在连接电缆的情况下运行应用程序:“npx react-native run-android”,则图像可见。断开数据线并在手机上重新打开应用程序后,图像将不可见。
      • @mtoninelli 我不知道这个问题 TBH。在我的设备上,图像显示完美。尝试卸载并重新安装。让我们知道什么有效。
      【解决方案5】:

      对于 iOS 14 也可以升级到最新版本的 react-native 0.63.3

      【讨论】:

        【解决方案6】:

        检查图像文件的名称或尝试重命名。在我的情况下,它是图像的名称。我重命名(删除了'-'字符)图像并且它起作用了。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-12-17
          • 1970-01-01
          • 2015-12-12
          • 1970-01-01
          • 2020-12-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多