【问题标题】:React Native iOS Release build stuck on old code but Debug build works fineReact Native iOS Release 构建卡在旧代码上,但 Debug 构建工作正常
【发布时间】:2020-03-18 08:06:08
【问题描述】:

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

例子:

我更改了我的任何 JS 文件中的标签,例如某些菜单的标题,当我使用 react-native run-ios 或如果在方案中选中“调试”时按下 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

【问题讨论】:

  • 你能试试这个 ios re-bundler 命令吗:react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios/assets
  • 嗨@Kuray-FreakyCoder-。它创建了一个新的 main.jsbundle,但是当我构建和运行时仍然没有改变任何东西。
  • 你能和我分享一个可重现的例子吗?
  • 我真的不知道如何分享一个可重现的示例。如果方案处于发布模式,我的应用程序会忽略我会做的任何更改。如果我运行 react-native run-ios 命令或将方案置于调试模式,它将正常工作。要上传到应用商店,我需要正确的发布模式。
  • 我测试 rn ios 应用程序的方法是:构建存档并上传,然后使用 TestFlight 应用程序进行测试

标签: ios xcode react-native build


【解决方案1】:

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

我终于找到了解决办法。

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

我在 /ios/ProjectName 外面有一个正确的,而旧的在那里。我只需要应用这个sn-p,它会生成一个新的干净的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 中

感谢大家的帮助。

【讨论】:

    【解决方案2】:

    存档前停止已经运行的节点 并启动服务器,现在制作存档

    npm start -- --reset-cache
    

    【讨论】:

      猜你喜欢
      • 2011-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 2020-02-05
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      相关资源
      最近更新 更多