首页 > 解决方案 > React Native iOS Release 构建停留在旧代码上,但 Debug 构建工作正常

问题描述

当我尝试从 in 构建我的 React Native AppXCode以在Release mode将其启动到生产之前进行检查时,它会卡在旧代码中。无论我在我的 JS 文件中进行什么更改,它都不会这样做。在调试模式下它不会发生,就像它应该的那样工作正常。

例子:

react-native run-ios我更改了我的任何 JS 文件中的标签,例如某些菜单的标题,当我使用或按下 XCode 的“播放”按钮时,如果在“调试”方案中被选中,它将起作用。相反,如果我选中“发布”,它会收取我什至不知道是哪个版本的应用程序的旧版本。

我已尝试投入生产,但仍然是旧版本。

所以,现在有一天我无法上传新版本,因为无论我做什么更改,发布模式都会忽略它。

我试图生成一个新的main.jsbundle,我已经清理了构建,Shift + CMD + K并且我也重新安装了我npm的没有解决方案。

你有什么主意吗?

编辑:

文件“AppDelegate.m”与它有什么关系吗?

这是我的 AppDelegate:

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"BottomNavigation"
                                            initialProperties:nil];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

标签: iosxcodereact-nativebuild

解决方案


正如我在这里发布的: https ://stackoverflow.com/a/59029751/8898886

最后我找到了解决方案。

问题是我生成的 main.jsbundle 放在错误的位置,同时有 2 个 main.jsbundle,旧的和损坏的和正确的。

我在 /ios/ProjectName 外面有一个正确的,而在那里有一个旧的。我只需要应用这个片段,它会生成一个新的和干净的main.jsbundle

react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios/assets

然后获取文件 main.jsbundle 和 assets 文件夹并将它们放在 /ios/ProjectName 中

谢谢大家的帮助。


推荐阅读