简体   繁体   English

[Cordova][Android] 在发布版本上运行时套接字未连接

[英][Cordova][Android] Sockets not connecting when running on release build

I'm currently trying to publish a cordova app on google play store... 我目前正在尝试在 Google Play 商店上发布 Cordova 应用程序...

However when I run the release build from the store the app does not connect to the sockets.但是,当我从商店运行发布版本时,应用程序不会连接到套接字。

I am using LaravelEcho with SocketIo client.我正在将 LaravelEcho 与 SocketIo 客户端一起使用。

  • cordova - 9.0.0 (cordova-lib@9.0.1)科尔多瓦 - 9.0.0 (cordova-lib@9.0.1)
  • angular - 8.1.2角度 - 8.1.2
  • socket.io - 2.1.4 socket.io - 2.1.4
  • laravel-echo - 1.6.1 laravel 回声 - 1.6.1

After I searched the problem I found some results about a permission, but I already have that.搜索问题后,我发现了一些有关权限的结果,但我已经有了。

<uses-permission android:name="android.permission.INTERNET" />

Is it possible to debug the app in the release mode?是否可以在发布模式下调试应用程序?

update更新

This is how I imported the NgxLaravelEchoModule这就是我导入 NgxLaravelEchoModule 的方式

NgxLaravelEchoModule.forRoot({ userModel: 'App.Models.User', notificationNamespace: 'App\\\\Notifications', options: { broadcaster: 'socket.io', host: environment.socketsURL } }),

update更新

I managed to pint an error message thrown by socket module我设法找出了套接字模块抛出的错误消息

xhr poll error

I spent hours upon hours searching for the answer to this question (and I know this post is old but perhaps it could help someone).我花了几个小时寻找这个问题的答案(我知道这篇文章很旧,但也许它可以帮助某人)。 Not one person could answer this.没有人能回答这个问题。 Though, I believe the true answer is that, by default, Android does not like http.不过,我相信真正的答案是,默认情况下,Android 不喜欢 http。 Instead, a solution is to use https on whatever your socket.io client is.相反,解决方案是在您的 socket.io 客户端上使用 https。 But that's annoying to setup.但设置起来很烦人。

A better solution is to allow http on the Android application.更好的解决方案是在 Android 应用程序上允许 http。 In your AndroidManifest.xml, find "application".在您的 AndroidManifest.xml 中,找到“应用程序”。 It should look like this by default:默认情况下它应该是这样的:

<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">

Append android:usesCleartextTraffic="true" to this to get the following:android:usesCleartextTraffic="true"附加到此以获得以下内容:

<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">

Compile your apk and run it on an Android device.编译您的 apk 并在 Android 设备上运行它。 And voila!瞧! You can now connect to your sockets on the release build.您现在可以连接到发布版本上的套接字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM