【问题标题】:Local images are not visible in React-Native app release build本地图像在 React-Native 应用程序发布版本中不可见
【发布时间】:2017-01-30 13:46:26
【问题描述】:

在我的 react-native 应用程序中,我有 "src" 文件夹,其中包括 Images 文件夹和屏幕文件夹。我的 screens 文件夹有各种 组件 我使用以下代码从 Images 使用本地图像。

<Image source={require('src/Images/logo.png')} />

logo.png 是放置在 Images 文件夹中的图像,还有很多这样的图像引用。现在所有这些图像在开发模式下都显示得很好,但是当我使用生成发布 apk 时gradlew assemblerelease 并在我的设备上安装了 apk 以这种方式引用的所有图像都会消失在某处。

我的 react-native 版本是 0.40。

【问题讨论】:

    标签: image local release react-native-android


    【解决方案1】:

    通过Chiranjhivi Ghimire的回答解决了 步骤 -

    1. 在 ../android/app/src/main/ 创建了 assets 文件夹
    2. 将此命令复制并粘贴到命令提示符中

    react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest安卓/app/src/main/res/

    1. 在 cmd gradle assemblerelease 中输入此命令。
    2. 完成

    可以在link找到 ios 的等效解决方案

    【讨论】:

    • 如果你的 React Native 项目目录没有 index.android.js 这个命令对我有用" react-native bundle --platform android --dev false --entry-file index.js -- bundle-output android/app/src/main/assets/index.bundle --assets-dest android/app/src/main/res/"
    • 我正在运行这些命令: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/ cd android &amp;&amp; ./gradlew clean &amp;&amp; ./gradlew assembleRelease &amp;&amp; ./gradlew installRelease 但是有些图像没有出现,而另一些图像正在出现。
    • @khateeb 这很奇怪,但是使用最新版本的 react-native 你应该用“index.bundle”替换“index.android.bundle”,请参阅 Mesorale 的评论
    • @ManjeetSingh 我试过了,但没有任何作用。
    • 我也有这个问题。运行 react-native bundle --platform android --dev false --entry-file app/index.js --bundle-output android/app/src/main/assets/index.bundle --assets-dest android/app/src/main/res/ 命令没有帮助。有什么建议吗?
    【解决方案2】:

    尝试运行此
    npm start --reset-cache

    【讨论】:

      猜你喜欢
      • 2019-01-31
      • 1970-01-01
      • 1970-01-01
      • 2022-06-22
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多