我有一个 React-Native 应用程序,我正在尝试以发布模式部署到我的手机。我可以将应用程序捆绑到手机上。数据库、视频和音频资产都在那里,但 UI 中没有显示任何图像。
我已经做了以下操作来"捆绑"我的应用程序:
- 在终端运行
react-native bundle --platfrom ios --dev false --entry-file index.ios.js --bundle-output main.jsbundle
的项目文件夹中 - 将对
main.jsbundle
文件的引用拖到myapp
文件夹下的 XCode 中 - 在 XCode 中,打开
AppDelegate.m
并取消注释jsCodeLocation = [[NSBundle mainBundle]…
- 打开
Product > Scheme > Edit Scheme
然后将Build Configuration
更改为Release
- 在项目导航器下选择"
myapp
",然后:在TARGETS: myappTests
>Build Phases
>Link Binary With Libraries
下按+
选择"Workspace
>libReact.a
"和"Add
">
当我尝试使用 myapp > targets > myapp > Bundle React Native code and images
中的 ../node_modules/react-native/packager/react-native-xcode.sh
设置在 XCode 中编译时,它失败并显示 error code 1
.
我已经看到了很多关于这个的帖子,我已经尝试过:
- 检查
Run script only when installing
- 然后应用安装但没有图像 - 向 react-native-xcode.sh 添加
source ~/.bash_profile
- 应用生成失败
任何帮助将不胜感激!
当你在生成bundle时,也把--assets-dest./
react-native bundle --platform ios --assets-dest ./ --dev false --entry-file index.ios.js --bundle-output iOS/main.jsbundle
它将生成main.jsbundle
和资产文件夹。转到您的Xcode,右键单击将文件添加到项目main.jsbundle
然后将文件添加到项目。同时拖放"资产"文件夹并选择"按引用创建"(注意:不要选择"创建组"(。
我正在使用 React 0.33,main.jsbundle正在使用assets(small a(文件夹,但生成Assets(Caps A(。我刚刚将生成的文件夹从资产更改为资产并将其导入 xcode,它开始工作
图像是在 xcode 中还是在文件系统中?,我在捆绑包参数中看不到--assets-dest
react-native bundle --minify --dev false --assets-dest ./ios --entry-file index.ios.js --platform ios --bundle-output ios/main.jsbundle
还可以将资产文件夹像捆绑包一样添加到 Xcode。
请注意,仅当正确需要图像资源时,才会复制图像资源,请参阅文档
for iOS 14 :转到此目录:node_modules/react-native/Libraries/Image并打开 RCTUIImageViewAnimated.m,然后将 else 条件添加到此部分:
if (_currentFrame) {
layer.contentsScale = self.animatedImageScale;
layer.contents = (__bridge id)_currentFrame.CGImage;
} else {
[super displayLayer:layer];
}
在你的 react 本机项目根目录中运行以下命令:
react-native bundle --entry-file='./index.js' --bundle-output='./main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'
并在 XCode 中添加项目中文件夹的引用。
我在构建阶段将资产文件夹作为一个整体添加>复制捆绑资源并运行它;
NPX React-native bundle --platform iOS --assets-dest ./--dev false --entry-file index.js --bundle-output ios/main.jsbundle
希望这对某人有所帮助。