'Cordova android app - Release build - could not connect to server
I am working on Cordova Application. This loads the list of customers on Application load using https url.
While running in debug mode (using cordova run android) application works fine, but when I create release build for the same application, application is not able to connect to server. giving error "unable to connect to server. Status 0".
Here is my technology stack trace.
- Cordova v4.0
- Cordova Android Platform v3.6.4
- Dojo Mobile 1.8.3
Update:
I found out that SSL certificate root was wrongly installed, which was treated by Andrroid browser as security issue. I found out this when I hit the certificate on android browser.
Now I have valid SSL certificate installed, verified on Android browser (after clearing cache) but still application is not able to connect to the URL.
It seems, somehow, android have cached the wrong certificate ?
Solution 1:[1]
I know this answer is over a year after the question was asked, but I hit the exact same issue when I published a Cordova app to the Android store for a particular client, and found this question a very helpful clue for my particular problem: Debug installed versions could connect to the client's servers, the signed release version could not.
It turns out that the issue was although we were connecting OK to servers with SSL certificates, (in this case Node.js servers,) from both web browsers, test tools like Postman, and with the debug app on devices, we needed to also provide the certificate chain with the certificate authority too on our servers before the release version would connect properly.
Solution 2:[2]
For anyone reaching this question having the same issue in "modern times":
Android versions 28+ need a secure connection to be setup in the manifest file, by default they are ignored in the debug build. For a TEST release build to work you can simply set
android:usesCleartextTraffic="true"
in the application tag of you manifest or setup it correctly following the infos at
https://developer.android.com/training/articles/security-config
Solution 3:[3]
may answer was so late,but I think this will useful for other person. I have the same problem and trying to fix it to different way.my problem was app build but it can not connect to the server.first I think it cause ajax have problem but it was true and I test it to another computer and it worked,
finally I do some way like check version gradlle and config.xml,
the content of my config.xml is =>
<?xml version='1.0.0' encoding='utf-8'?>
<widget id="com.example.dr" version="1.0.0" android-versionCode="5" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>myapp</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="[email protected]" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="*" />
<allow-intent href="*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<preference name="SplashMaintainAspectRatio" value="true|false" />
<preference name="ShowSplashScreenSpinner" value="false"/>
<platform name="android">
<icon src="www/img/logo.png" density="ldpi" />
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
and when I check version of gradle was 2.2, I changed it to higher verison and it build and connected to server.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Neil Cresswell |
| Solution 2 | snoob dogg |
| Solution 3 |
