我一直试图推出AwesomeProject应用程序两天,但没有成功。
我一步一步地按照入门教程(适用于Windows / Android的v0.42)进行操作。
这就是我所做的:
react-native init AwesomeProject
成功。
cd ./AwesomeProject
react-native run-android
我得到以下内容: 为react-packager启动一个新的命令提示符窗口,然后启动然后永远等待:
Scanning 557 folders for symlinks in C:\xxx\zzz\yyy\workspace\react-
native\AwesomeProject\node_modules (31ms)
┌────────────────────────────────────────────────────────────────────────────┐
│ Running packager on port 8081. │
│ │
│ Keep this packager running while developing on any JS projects. Feel │
│ free to close this tab and run your own packager instance if you │
│ prefer. │
│ │
│ https://github.com/facebook/react-native │
│ │
└────────────────────────────────────────────────────────────────────────────┘
Looking for JS files in
C:\xxx\yyy\zzz\workspace\react-native\AwesomeProject
Loading dependency graph...
React packager ready.
Loading dependency graph, done.
在模拟器,红色屏幕上显示无用的消息"无法获取BatchedBridge,请确保您的包装正确包装并且#34;
"Could not get BatchedBridge, ...
在第一个命令提示符(我称之为run-android):
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat install
Debug...
Using maven environment 'default'
:app:preBuild UP-TO-DATE
[... everything seems ok...]
:app:installDebug
Installing APK 'app-debug.apk' on 'emulator-5554 - 4.4.2'
Installed on 1 device.
BUILD SUCCESSFUL
Total time: 1 mins 44.307 secs
Running C:\dev\Android\sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081
tcp:8081
error: closed
Could not run adb reverse: Command failed: C:\dev\Android\sdk/platform-tools/adb
-s emulator-5554 reverse tcp:8081 tcp:8081
Starting the app on emulator-5554 (C:\dev\Android\sdk/platform-tools/adb -s emul
ator-5554 shell am start -n com.awesomeproject/.MainActivity)...
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a
security risk. Please fix.
Starting: Intent { cmp=com.awesomeproject/.MainActivity }
在Android Studio的Android显示器中,我用于模拟器:
02-08 03:45:31.850 2472-2533/com.awesomeproject E/unknown:React: Exception in native call from JS
com.facebook.react.devsupport.JSException: Could not get BatchedBridge, make sure your bundle is packaged correctly
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:136)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
at java.lang.Thread.run(Thread.java:841)
Caused by: com.facebook.jni.CppException: Could not get BatchedBridge, make sure your bundle is packaged correctly
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:136)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
at
java.lang.Thread.run(Thread.java:841)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
at java.lang.Thread.run(Thread.java:818)
如果我在模拟器中点击重新加载(R,R),我现在有错误屏幕"无法连接到开发服务器。"
Could not connect to development server...
此时不知道该怎么做。
这https://stackoverflow.com/a/38874952/3249701绝对没有。
这也不是https://stackoverflow.com/a/40500277/3249701
我在哪里可以获得正确的堆栈跟踪或相关的日志消息,以了解我哪里出错了?
谢谢,
编辑:
现在,React Packager还没有完全启动。关注消息后,它会冻结:
Scanning 557 folders for symlinks in C:\xxx\yyy\zzz\workspace\AwesomeProject\node_modules (61ms)
┌────────────────────────────────────────────────────────────────────────────┐
│ Running packager on port 8081. │
│ │
│ Keep this packager running while developing on any JS projects. Feel │
│ free to close this tab and run your own packager instance if you │
│ prefer. │
│ │
│ https://github.com/facebook/react-native │
│ │
└────────────────────────────────────────────────────────────────────────────┘
Looking for JS files in
C:\xxx\yyy\zzz\workspace\AwesomeProject
Loading dependency graph...
React packager ready.
Loading dependency graph, done.
我尝试在开发设置中设置我的IP(来自> ipconfig),但没有成功。我回到了10.0.1.1:8081,但现在包管理器根本无法获得应用程序。我尝试的越多,它就越混乱。
在模拟器上我试图摇动它,进入开发设置,将主机设置为空,而不是重新加载。我收到了以下错误:
02-07 16:40:16.056 2949-2949/com.awesomeproject E/unknown:React: Exception in native call
com.facebook.react.devsupport.DebugServerException: Could not connect to development server.
Try the following to fix the issue:
• Ensure that the packager server is running
• Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices
• Ensure Airplane Mode is disabled
• If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device
• If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081
URL: http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false
at com.facebook.react.devsupport.DevServerHelper$5.onFailure(DevServerHelper.java:296)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.io.IOException: unexpected end of stream on okhttp3.Address@59b3133f
at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:201)
at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:53)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
at okhttp3.RealCall.access$100(RealCall.java:33)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.io.EOFException: \n not found: size=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:215)
at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:53)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
at okhttp3.RealCall.access$100(RealCall.java:33)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
答案 0 :(得分:1)
我有同样的问题。我还没有找到完整的解决方案,但我可以通过遵循Akhi的指令间接启动设备中的应用程序。
react-native bundle --entry-file index.android.js --platform android --dev
false --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res/.
此步骤未显示任何错误。我仍在等待React-native的完整解决方案。
答案 1 :(得分:0)
如果出现错误,请在终端上的项目根文件夹目录中运行npm test
,然后它会显示问题。如果没有问题,请运行命令npm start
并在任何Android设备上从android studio运行您的项目。启动后,将机器的IP地址设置为开发设置,然后设置端口8081,然后重新加载。
答案 2 :(得分:0)
答案是打开两个终端
终端1:转到react-native项目并运行命令react-native start
终端2:转到react-native项目并运行命令react-native run-android
这个错误不会来。尝试这个解决方案。它会工作。在本机文档中缺少这个东西。
答案 3 :(得分:0)
检查权限并允许弹出窗口