apache / cordova

Apache Cordova
https://cordova.apache.org/
583 stars 61 forks source link

[Ionic] Cordova app is not connecting to the sockets api in release build. #197

Closed cigogma closed 4 years ago

cigogma commented 4 years ago

Bug Report

(ATTENTION: this is happening just with the tag --release ) App is not connecting to the sockets api in release build.

Problem

I cureently built an ionic app based on sockets connection, everything works just fine when i am in debug mode.. however when i move to release ( --release attribute ) the app is no longer connecting to the api endpoint. sockets is trowing the fallowing message xhr poll error

What is expected to happen?

connect to the api endpoint.

What does actually happen?

not connecting to the api endpoint.

Information

I am currently using the fallowing packages

 "dependencies": {
    "@angular/animations": "^8.2.14",
    "@angular/common": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/forms": "~8.1.2",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/router": "~8.1.2",
    "@ionic-native/call-number": "^5.20.0",
    "@ionic-native/core": "^5.19.1",
    "@ionic-native/diagnostic": "^5.19.1",
    "@ionic-native/file": "^5.19.1",
    "@ionic-native/file-transfer": "^5.19.1",
    "@ionic-native/geolocation": "^5.19.1",
    "@ionic-native/google-maps": "^5.5.0",
    "@ionic-native/http": "^5.19.1",
    "@ionic-native/location-accuracy": "^5.19.1",
    "@ionic-native/splash-screen": "^5.19.1",
    "@ionic-native/status-bar": "^5.19.1",
    "@ionic/angular": "^4.7.1",
    "@ionic/storage": "^2.2.0",
    "@mapbox/polyline": "^1.1.0",
    "@types/socket.io": "^2.1.4",
    "@types/socket.io-client": "^1.4.32",
    "angular-laravel-echo": "git+https://github.com/chancezeus/angular-laravel-echo.git",
    "call-number": "^1.0.1",
    "cordova-android": "^8.1.0",
    "cordova-plugin-advanced-http": "^2.3.1",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-googlemaps": "^2.6.2",
    "cordova-plugin-request-location-accuracy": "git+https://github.com/razvang10/cordova-plugin-request-location-accuracy.git",
    "cordova-sqlite-storage": "^4.0.0",
    "cordova.plugins.diagnostic": "^5.0.1",
    "core-js": "^2.5.4",
    "laravel-echo": "^1.6.1",
    "ngx-laravel-echo": "^1.0.26",
    "rxjs": "^6.5.4",
    "socket.io-client": "^2.3.0",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.801.2",
    "@angular-devkit/build-angular": "^0.803.23",
    "@angular-devkit/core": "~8.1.2",
    "@angular-devkit/schematics": "~8.1.2",
    "@angular/cli": "8.1.3",
    "@angular/compiler": "~8.1.2",
    "@angular/compiler-cli": "~8.1.2",
    "@angular/language-service": "~8.1.2",
    "@ionic/angular-toolkit": "^2.1.1",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.2.1",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^4.1.3",
    "cordova-plugin-splashscreen": "^5.0.3",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-whitelist": "^1.3.4",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.5.1",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  },

Command or Code

ionic cordova build android --release --prod

Environment, Platform, Device

Platform: android

Device: any

Version information

Cordova : 9.0.0 (cordova-lib@9.0.1) Ionic: 6.1.0 Operating System: Windows Android Studio: 3.5 Platform version: API 29 SDK: 26.1.1

Checklist

brodybits commented 4 years ago

We do not support issues with Ionic CLI. Please seek support in appropriate channels for use with Ionic CLI.

cigogma commented 4 years ago

with the same code and everything works on api level 27 but on 28+ it does not... I dont think thats a ionic issue @brodybits

breautek commented 4 years ago

with the same code and everything works on api level 27 but on 28+ it does not... I dont think thats a ionic issue @brodybits

Are you able to provide a sample reproduction app that contains exactly what is needed to reproduce the issue and nothing more? (pure cordova, no frameworks like ionic, angular, etc).

The reason why Brody says we cannot support issues with Ionic is because frameworks can change the behaviour so it can be really hard to identify or reproduce issues, and by having frameworks or libraries, it opens up the possibility for the cause drastically. https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md

Alternatively, if you provide us with a full error message, we may be able to provide some more insight. XHR Poll Error is a generic error message from the socket library you are using. I don't know too much about socket.io, but I suspect there are probably other relevant information that we are missing here. (Perhaps check the network tab?)

everything works on api level 27 but on 28+ it does not

This is just a guess, but one notable change between API 27 and API 28 is that network traffic by default must be secure (therefore they need to use https protocol and your server needs to have a valid SSL certificate).

cigogma commented 4 years ago

Are you able to provide a sample reproduction app that contains exactly what is needed to reproduce the issue and nothing more? (pure cordova, no frameworks like ionic, angular, etc).

You can reproduce it just by creating an app adding socket io client and running the app in release mode.

Alternatively, if you provide us with a full error message, we may be able to provide some more insight. XHR Poll Error is a generic error message from the socket library you are using. I don't know too much about socket.io, but I suspect there are probably other relevant information that we are missing here. (Perhaps check the network tab?)

Well @breautek the thing is that it works with api 28+ just in debug mode but in release mode it does not connect... I cannot debug it, check the network tab or anything releated to that.

This is just a guess, but one notable change between API 27 and API 28 is that network traffic by default must be secure (therefore they need to use https protocol and your server needs to have a valid SSL certificate).

The server that im trying to connect to is secure and it has a valid ssl certificate.

breautek commented 4 years ago

I used the socket io example chat app, deployed to an android simulator running the latest version of cordova-android, which targets API 28. I tried in debug mode to confirm that it works as you stated, and it does. I have also ran in release mode, and it still worked.

We will need a reproduction app from you (please follow the instructions at https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md). Please remember to only include the absolute minimum code required to demonstrate the issue.

cigogma commented 4 years ago

I did try with a reproduction app... I didnt work in the first place. I figured out that even if the connection was encrypted with a valid ssl certificate, android firewall probably was blocking the connection because the socket.io was running on port 6001. I solved the issue by running the socket.io on port 443. Thanks!

breautek commented 4 years ago

Glad that we got to the bottom of it :smile: