简体   繁体   English

适用于 iOS 的 React Native 发布包中没有图像

[英]No Images in react native release bundle for iOS

I've looked high and low at solutions to this problem, but none of them have worked.我已经对这个问题的解决方案进行了高低审视,但没有一个奏效。

on iOS, I'm making a release bundle with react-native bundle --dev false --assets-dest ./ios/Bundle --entry-file index.js --platform ios --bundle-output ./ios/Bundle/main.jsbundle在 iOS 上,我正在制作一个带有react-native bundle --dev false --assets-dest ./ios/Bundle --entry-file index.js --platform ios --bundle-output ./ios/Bundle/main.jsbundle

Afterwards, I'm adding the Bundle directory which includes the assets directory and the main.jsbundle to my project in XCode.之后,我将包含资产目录和 main.jsbundle 的 Bundle 目录添加到我在 XCode 中的项目中。

Then I change the Run scheme to work on the Release configuration, and run the project on a physical device.然后我更改运行方案以处理发布配置,并在物理设备上运行项目。

React Native finds the bundle, but none of the static assets show up. React Native 找到了包,但没有显示任何静态资产。

I'm on React Native 0.48我在 React Native 0.48

Incase anyone else has a similar problem and needs some ideas where to look..柜面其他人有类似的问题,需要一些想法在哪里看..

Check your xcode build logs and to see where your bundle is being created probably something like检查您的 xcode 构建日志并查看您的包的创建位置可能类似于

/Users/johnsmith/Library/Developer/Xcode/DerivedData/MyApp-asde14dwefda878/Build/Products/Release-iphonesimulator/MyApp.app

Inspect and make sure that main.jsbundle and assets/ are both at the top level.检查并确保main.jsbundleassets/都在顶层。 If they're not then check your arguments to the bundle command (called by the bundle react native code and images build phase by the react-native-xcode.sh command) the defaults should be fine.如果它们不是,则检查您对 bundle 命令的参数(由bundle react native code and images构建阶段由react-native-xcode.sh命令react-native-xcode.sh ),默认值应该没问题。 you can also use set -x to print out more info about what's being called, or click show environment variables in build log您还可以使用set -x打印出有关正在调用的内容的更多信息,或单击show environment variables in build log

Assuming that everything is in the correct location...then try looking where the code is really looking for the image假设一切都在正确的位置......然后尝试查看代码真正寻找图像的位置

import background from "../../assets/background.png"
alert(Image.resolveAssetSource(background).uri);

Inspect in file explorer and see if you can find the file.在文件资源管理器中检查并查看是否可以找到该文件。 The folder my code was looking in was this:我的代码正在查找的文件夹是这样的:

/Users/.../Library/Developer/CoreSimulator/Devices/718SDF9995-1123D6-46A8-93DD-830963FC4372/data/Containers/Data/Application/25C8SG9C-2CSA-4891-BDFD-B6B37A3B4022/Library/Application Support/.expo-internal/

In my case I had ejected from expo and the file was there under a hash but the code was looking for it as ../assets/background.png It was using expo-asset to resolve the file in release (not metro as in debug), the fix was to add在我的情况下,我已经从 expo 中弹出并且文件在哈希下,但代码正在寻找它作为../assets/background.png它使用 expo-asset 来解析发布中的文件(而不是调试中的地铁),修复方法是添加

../node_modules/expo-updates/scripts/create-manifest-ios.sh

to the end of the Bundle React Native code and images build phase and to add import 'expo-updates' to the top of my App.tsx fileBundle React Native code and images构建阶段的末尾,并将 import 'expo-updates' 添加到我的App.tsx文件的顶部

Another idea would be to add an external image and see if it can load that.另一个想法是添加一个外部图像,看看它是否可以加载。

source={{uri:'https://......../...png'}}

There's also the problem with Ios14 images that can be fixed by updating react-native or using npx react-native-fix-image but that would also affect dev builds Ios14 图像也存在问题,可以通过更新 react-native 或使用npx react-native-fix-imagenpx react-native-fix-image但这也会影响开发版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM