最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】ReactNative项目运行到iPhone真机出错:Error reading bundle main.jsbundle

iphone crifan 4977浏览 0评论

去参考ReactNative的一个项目:

去运行到模拟器是OK的,

运行到iPhone真机时:

出错:

Error reading bundle /var/containers/Bundle/Application/AF65A6AE-65A7-4861-8BB5-CD74A6F7D7F7/iReading.app/main.jsbundle
RCTFatal
__28-[RCTCxxBridge handleError:]_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_callback_4CF
<redacted>
<redacted>
CFRunLoopRunSpecific
GSEventRunModal
UIApplicationMain
main
<redacted>

react native Error reading bundle /var/containers/Bundle/Application main.jsbundle

react native Error reading bundle  main.jsbundle

[0.46.3] fails to run on device · Issue #14912 · facebook/react-native

此处我的node版本是8.0.0:

➜  reading git:(master) ✗ node -v
v8.0.0
➜  reading git:(master) ✗ react-native -v
react-native-cli: 2.0.1
react-native: 0.49.3

Solving React Native’s "No bundle url present" Error – Andrew Bancroft

去试试:

➜  reading git:(master) ✗ pwd
/Users/crifan/dev/dev_root/ReactiveNative/lib/reading
➜  reading git:(master) ✗ cd ios
➜  ios git:(master) ✗ rm -rf build
➜  ios git:(master) ✗ cd ..
➜  reading git:(master) ✗ react-native run-ios

此处想起来了:

之前试过react-native run-ios,但是最后编译出错了。没去管。

直接去ios文件夹中双击reading.xcodeproj去运行的。

估计和编译出错有关系?

这个是最终编译成功了:

** BUILD SUCCEEDED **
The following commands produced analyzer issues:
    Analyze /Users/crifan/dev/dev_root/ReactiveNative/lib/reading/node_modules/react-native/ReactCommon/yoga/yoga/YGNodeList.c
    Analyze /Users/crifan/dev/dev_root/ReactiveNative/lib/reading/node_modules/react-native/ReactCommon/yoga/yoga/Yoga.c
    Analyze Base/RCTModuleMethod.mm
(3 commands with analyzer issues)
Installing build/Build/Products/Debug-iphonesimulator/iReading.app
Launching com.richardcao.reading.crifan
com.richardcao.reading.crifan: 57258

再去打开:

reading.xcodeproj

问题依旧。

去关闭掉之前的terminal,再重试,结果:

问题依旧:

此处ss不是全局代理,已经是 自动代理,不会是由于代理导致网络无法访问。

卸载掉iPhone真机上已经安装了的app,重新试试,问题依旧。

Xcode项目中搜:

Error reading bundle

找到:

  facebook::react::BundleHeader header;
  size_t readResult = fread(&header, sizeof(header), 1, bundle);
  fclose(bundle);
  if (readResult != 1) {
    if (error) {
      *error = [NSError errorWithDomain:RCTJavaScriptLoaderErrorDomain
                                   code:RCTJavaScriptLoaderErrorFailedReadingFile
                               userInfo:@{NSLocalizedDescriptionKey:
                                            [NSString stringWithFormat:@"Error reading bundle %@", scriptURL.path]}];
    }
    return nil;
  }

重启iPhone真机,问题依旧。

error reading bundle react native

Wrong error message when failing to load JS bundle [iOS] · Issue #799 · Microsoft/react-native-code-push

此处也是:

AppDelegate.m

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;
  
#ifdef DEBUG
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  jsCodeLocation = [CodePush bundleURL];
  [Bugly startWithAppId:@"b0c9343009"];
#endif
  
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"reading"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

难道是:

此处运行到模拟器时debug,运行到真机是release,此处release时,是CodePush,所以找不到:main.jsbundle??

不过在:

CodePush.m

看到的确是通过:

// These values are used to save the NS bundle, name, extension and subdirectory
// for the JS bundle in the binary.
static NSBundle *bundleResourceBundle = nil;
static NSString *bundleResourceExtension = @"jsbundle";
static NSString *bundleResourceName = @"main";
static NSString *bundleResourceSubdirectory = nil;

定义了main.jsbundle了啊。

Wrong error message when failing to load JS bundle [iOS] · Issue #799 · Microsoft/react-native-code-push

难道是:

react-native-code-push自己有bug?

此处:

"react-native-code-push": "^5.1.3-beta”,

看看上面的帖子中的版本?

Improved logic to show error msg dependent on debug/release config (#… · Microsoft/react-native-code-push@afc7140

已经是最新合并后的代码了。

Error reading bundle /var/containers/Bundle/Application

Unable to open bundled realm file on real device · Issue #4809 · realm/realm-cocoa

其是写入,我这里没有,只是只读。

暂时不继续深入找原因了。

抽空再继续。

转载请注明:在路上 » 【未解决】ReactNative项目运行到iPhone真机出错:Error reading bundle main.jsbundle

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 朋友,这个问题后来有没有解决办法啊
    拉拉链6年前 (2019-04-30)回复
93 queries in 0.199 seconds, using 22.07MB memory