androidangularcordovasocketsionic-framework

Sockets not connecting when running on release build


I'm currently trying to publish a cordova app on google play store... 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.

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?

This is how I imported the NgxLaravelEchoModule

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

I managed to pint an error message thrown by socket module

xhr poll error


Solution

  • 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. Instead, a solution is to use https on whatever your socket.io client is. But that's annoying to setup.

    A better solution is to allow http on the Android application. In your AndroidManifest.xml, find "application". 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:

    <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. And voila! You can now connect to your sockets on the release build.