微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React原生客户端在Android中使用但在ios中工作时未连接到服务器

如何解决React原生客户端在Android中使用但在ios中工作时未连接到服务器

通过 https://github.com/improbable-eng/grpc-web/tree/master/client/grpc-web-react-example 提供的示例,我通过将 ts 文件转换为 javascript 文件创建了一个 grpc 客户端,它使用 grpc-react-native-transport 并返回要显示的书名。它适用于 ios,但是当我在 android 模拟器中运行代码时,我收到状态代码 2,即未知。请帮我弄清楚。

我希望服务器返回书的详细信息,我会获取书名并使其显示在 android 模拟器上。

您可以在 https://github.com/S7-Works/grpc-react 处检查代码并进行 android 构建和检查。

Android 模拟器使用 Android10(API 级别 29),我们在遇到安全错误后设置了 android:usesCleartextTraffic="true"。

使用的相关软件版本:

"@improbable-eng/grpc-web": "^0.13.0","@improbable-eng/grpc-web-react-native-transport": "^0.13.0","google-protobuf": "^3.14.0","react": "16.13.1","react-native": "0.63.4","node":"12.18.4"

构建日志: npm 运行安卓

gRPCAPP1@0.0.1 安卓 react-native run-android

info 运行 jetifier 以将库迁移到 AndroidX。您可以使用“--no-jetifier”标志禁用它。 Jetifier 找到了 967 个要转发 Jetify 的文件。使用 4 个工人... info JS 服务器已经在运行。 信息正在安装应用程序...

任务 :app:stripDebugDebugSymbols 最新版

Compatible side by side NDK version was not found.

任务:app:installDebug

04:31:12 V/ddms: execute: running am get-config
04:31:12 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1
04:31:12 V/ddms: execute: returning
Installing APK 'app-debug.apk' on 'Pixel_3a_Edited_1_API_29(AVD) - 10' for app:debug
04:31:12 D/app-debug.apk: Uploading app-debug.apk onto device 'emulator-5554'
04:31:12 D/Device: Uploading file onto device 'emulator-5554'
04:31:12 D/ddms: Reading file permision of D:\s7works\grpc-web\client\gRPCAPP\gRPCAPP1\android\app\build\outputs\apk\debug\app-debug.apk as: rwx------
04:31:14 V/ddms: execute: running pm install -r -t "/data/local/tmp/app-debug.apk"
04:31:16 V/ddms: execute 'pm install -r -t "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1
04:31:16 V/ddms: execute: returning
04:31:16 V/ddms: execute: running rm "/data/local/tmp/app-debug.apk"
04:31:16 V/ddms: execute 'rm "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1
04:31:16 V/ddms: execute: returning
Installed on 1 device.

Deprecated Gradle features were used in this build,making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 25s
27 actionable tasks: 2 executed,25 up-to-date
info Connecting to the development server...
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.grpcapp1/.MainActivity }

metro-serer 日志:

[Fri Feb 12 2021 16:34:11.488] BUNDLE ./index.js 
[Fri Feb 12 2021 16:34:20.356] LOG Running "gRPCAPP1" with {"roottag":11} 
[Fri Feb 12 2021 16:34:20.360] WARN Require cycle: node_modules\react-nativ e\Libraries\Network\fetch.js -> node_modules\whatwg-fetch\dist\fetch.umd.js -> n ode_modules\react-native\Libraries\Network\fetch.js Require cycles are allowed,but can result in uninitialized values. Consider ref actoring to remove the need for a cycle. App@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:991 13:36 RCTView RCTView AppContainer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify= false:68158:22 
[Fri Feb 12 2021 16:34:20.455] LOG status 2 msg null

解决方法

我试图查看您的代码,但得到了一个 404 页面。如果你更新你的链接,我相信你会更成功地获得帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。