使用静态 jsbundle 为 iOS 设备构建时“不变违规:应用程序 AwesomeProject 尚未注册”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29287987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Invariant Violation: Application AwesomeProject has not been registered" When building for iOS device with static jsbundle
提问by cmp
First off, I don't know react, but I figured deploying to an iOS device instead of the simulator wouldn't be too difficult to do with the docs. They were a bit sparse but I got somewhere and now I'm stuck. I created a main.jsbundle and added it to the Xcode project and uncommented the line in AppDelegate.m.
首先,我不知道反应,但我认为部署到 iOS 设备而不是模拟器不会太难用文档来做。他们有点稀疏,但我到了某个地方,现在我被卡住了。我创建了一个 main.jsbundle 并将它添加到 Xcode 项目并取消注释 AppDelegate.m 中的行。
When I deploy it I get this error:
当我部署它时,我收到此错误:
2015-03-26 16:13:08.538 AwesomeProject[4753:2477032] >
RCTJSLog> "Running application "AwesomeProject" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF"
2015-03-26 16:13:08.547 AwesomeProject[4753:2477032] >
RCTJSLog> "Error:
stack:
runApplication main.jsbundle:33769
jsCall main.jsbundle:7157
_callFunction main.jsbundle:7404
applyWithGuard main.jsbundle:877
guardReturn main.jsbundle:7206
callFunctionReturnFlushedQueue main.jsbundle:7413
URL: file:///private/var/mobile/Containers/Bundle/Application/DBC0DAF4-B568-4CF5-B156-9EFEE4E7FF4A/AwesomeProject.app/main.jsbundle
line: 1536
message: Invariant Violation: Application AwesomeProject has not been registered."
2015-03-26 16:13:08.723 AwesomeProject[4753:2477032] >
RCTJSLog> "#CLOWNTOWN (error while displaying error): Network request failed"
回答by xanadont
I'm pretty sure @krazyeom's fix has nothing to do with this error. In my case, I fixed this by quitting the terminal that was running from a previous test app I had run. It seems the terminal was confused and was still hooked to a process whose project was no longer loaded in XCode. Try the following:
我很确定@krazyeom 的修复与此错误无关。就我而言,我通过退出从我之前运行的测试应用程序运行的终端来解决此问题。终端似乎很困惑,并且仍然连接到一个项目不再加载到 XCode 的进程。请尝试以下操作:
- Shut the Terminal spawned by React Native.
- Shut down XCode completely (may not be necessary).
- Re-open everything and re-run.
- 关闭 React Native 生成的终端。
- 完全关闭 XCode(可能没有必要)。
- 重新打开一切并重新运行。
回答by tadeuzagallo
Your problem shouldn't have anything to do with the console, if you properly bundled your javascript into the ios app it wont be trying to talk to dev server, it'll just get the javascript from the bundle.
您的问题应该与控制台无关,如果您将 javascript 正确捆绑到 ios 应用程序中,它就不会尝试与开发服务器通信,它只会从捆绑包中获取 javascript。
From the error message I'd guess that you might have renamed your main component. Be sure that the 'AppName'
you pass into the
从错误消息我猜你可能已经重命名了你的主要组件。确保'AppName'
你通过
AppRegistry.registerComponent('AppName' /* <- */, ... )
AppRegistry.registerComponent('AppName' /* <- */, ... )
matches with the @"AppName"
on your AppDelegate.m
on the call for
与@"AppName"
您AppDelegate.m
通话中的
[[RCTRootView alloc] initWithBundleUrl:...
moduleName:@"AppName" // <-
launchOptions:...
回答by Nickwanhere
It is because the react-native server is still watching the old one. You need to shut the server down first.
这是因为 react-native 服务器还在看旧的。您需要先关闭服务器。
You could just kill the process.
你可以杀死这个过程。
In terminal
在终端
ps aux | grep react
Kill or pkill the process and then
杀死或 pkill 进程,然后
npm start
回答by alucic
AppRegistry defines the entry point to the application and provides the root component.
AppRegistry 定义应用程序的入口点并提供根组件。
Your first param doesn't match your project name.
您的第一个参数与您的项目名称不匹配。
AppRegistry.registerComponent('AwesomeProject', () => YourMainComponent);
First param of registerComponent
has to be your project name, second param is anonymous function that returns your root react component.
第一个参数registerComponent
必须是您的项目名称,第二个参数是返回您的根反应组件的匿名函数。
If first param doesn't match xcode project name, you get that error that your application has not been registered.
如果第一个参数与 xcode 项目名称不匹配,您会收到您的应用程序尚未注册的错误。
In case you don't have AppRegistry in the scope you can call it like this
React.AppRegistry.registerComponent
or you can assign it to the AppRegistry
var
如果您在范围内没有 AppRegistry,您可以像这样调用它,
React.AppRegistry.registerComponent
或者您可以将它分配给AppRegistry
var
var {
AppRegistry
} = React;
回答by wickey liang
AppRegistry.registerComponent('abc',() => ***);
the 'abc'
must be the same as the moduleName:@'abc'
in the file name AppDelegate.m
在'abc'
必须相同moduleName:@'abc'
的文件名AppDelegate.m
回答by Dawan
I had the same issue. I solved it by giving the same name to both AppDelegate's moduleNameand AppRegistry.registerComponent
我遇到过同样的问题。我通过为AppDelegate 的 moduleName和AppRegistry.registerComponent赋予相同的名称来解决它
If you are running the app with $ react-native run-ios
you will need to rename the moduleName
field in ./ios/[project name]/AppDelegate.m
to match the new name of the project. Refresh the phone simulator and it should show the new code.
如果您正在运行应用程序,$ react-native run-ios
您将需要重命名该moduleName
字段./ios/[project name]/AppDelegate.m
以匹配项目的新名称。刷新手机模拟器,它应该会显示新代码。
回答by Marques Woodson
Did you change the name of the app that you're registering? I started the app with the name 'tricky', then later changed the name in this line:
您是否更改了正在注册的应用程序的名称?我以“棘手”的名称启动了该应用程序,然后在这一行中更改了名称:
AppRegistry.registerComponent('MyNewApp', () => MyNewApp);
and I started getting the invariant error.
我开始得到不变的错误。
回答by codebased
I am not fan of closing down everything so I dig this further.
我不喜欢关闭所有东西,所以我进一步挖掘。
All I had to do is in my terminal window, I ran this command:
我所要做的就是在我的终端窗口中,我运行了这个命令:
../lala/node_modules/react-native/packager/launchPackager.command ; exit;
My project name was "lala" , so find that there is node_modules in your project too.
我的项目名称是 "lala" ,所以发现你的项目中也有 node_modules 。
replace lala with your project name it should work.
用你的项目名称替换 lala 它应该可以工作。
If there is an error says port is already in use:
如果有错误表示端口已被使用:
ERROR Packager can't listen on port 8081
Then you have two choices:
那么你有两个选择:
- Kill already running program.
- Or Change the port by going into :
../lala/node_modules/react-native/packager/packager.js
then find your port number, example 8081, and replace with the port number that is not in use.
- 杀死已经运行的程序。
- 或者通过进入更改端口:
../lala/node_modules/react-native/packager/packager.js
然后找到您的端口号,例如 8081,并替换为未使用的端口号。
var options = parseCommandLine([{ command: 'port', default: 8082, }, {
var options = parseCommandLine([{ command: 'port', default: 8082, }, {
Save this file and then run the above command again.
保存此文件,然后再次运行上述命令。
This way I can run multiple react(ors).
这样我就可以运行多个反应(或)。
回答by Jerry Chou
Reference a nameless person.
引用一个无名的人。
it works for me.
这个对我有用。
I had almost the same problem you currently have a few days ago. For me it was a real device.
几天前,我遇到了与您目前遇到的几乎相同的问题。对我来说,这是一个真正的设备。
From all my research, the solution that worked for me is the following:
根据我的所有研究,对我有用的解决方案如下:
- When you launch your app by typing react-native run-android, the error appears.
- So, reach your directory containing "adb.exe" ( for me it was
C:\Users\username\AppData\Local\Android\Sdk\platform-tools\
) - open a terminal from here. And type adb reverse tcp:8081 tcp:8081
- Then, by reloading the app on the phone, it should work.
- 当您通过键入 react-native run-android 启动您的应用程序时,会出现错误。
- 因此,到达包含“adb.exe”的目录(对我来说是
C:\Users\username\AppData\Local\Android\Sdk\platform-tools\
) - 从这里打开一个终端。然后输入 adb reverse tcp:8081 tcp:8081
- 然后,通过在手机上重新加载应用程序,它应该可以工作。
回答by Simar
Got the same error, restarting everything including the xcode and terminal worked for me.
遇到同样的错误,重新启动包括 xcode 和终端在内的所有内容对我有用。