[React Native]Invariant Violation: Application has not been registered
描述:这个是说xxx这个项目没有注册过
这个错误的根本原因是根目录./index.ios.js中
AppRegistry.registerComponent(‘项目名’,() => …);
与./ios/项目名/appDelegate.m中的
RCTRootView*rootView = [[RCTRootViewalloc]initWithBundleURL:jsCodeLocation
moduleName:@“项目名” launchOptions:launchOptions];
或是./android/app/src/main/java/com/项目名/MainActivity.java中的
mReactRootView.startReactApplication(mReactInstanceManager, “项目名”, null);
没有保持一致。
解决方案:
- 步骤一 修改对应的module Name
RCTRootView*rootView = [[RCTRootViewalloc]initWithBundleURL:jsCodeLocation
- 步骤二
./index.ios.js
修改项目名称
AppRegistry.registerComponent('xxx', () => xxx);
- 以上修改后还是不行的话
1.关闭由React Native生成的终端
2.关闭xcode
3.重新编译
(这个是让你clean全部,重新run一遍,同时如果react native一次有多个程序在运行,需要关闭,只能运行1个)