I've got a PhoneGap app that's working fine on iOS but when setup for a release build, does not work on Android.
I'm using the Phonegap CLI to create my application.
$ phonegap --version
4.2.0-0.24.2
The config.xml options for network access and whitelisting have been set:
<access origin="*" />
<feature name="http://api.phonegap.com/1.0/network" />
I've verified that my AndroidManifest.xml is requesting internet permission:
<uses-permission android:name="android.permission.INTERNET" />
My API returns the appropriate ACCESS-CONTROL-ALLOW-ORIGIN
header value:
Access-Control-Allow-Origin: *
For good measure I've also added this to my JS:
$.support.cors = true;
If I set the android remote debugging attribute so that I can connect from chrome://inspect
, then the network requests succeed and all is right with the world:
<application android:debuggable="true" ... >
However, if I simply remove that android:debuggable="true"
so that I can submit to the play store, recompile, and test again, then my cross-domain ajax requests fail. When they fail, they're returning with jqXHR.status=0
and jqXHR.readyState=0
, which in my experience indicates that the pre-flight OPTIONS request has failed for some reason.
Unfortunately, when I've enabled debugging and I connect to view the network requests, everything works -- so I can't see what might be wrong. I've restored to alert()
-ing various things to try and figure out what's going on... but I'm not getting any further.
I can also run my application in a browser on my laptop using a file://
url (which is how it's opened in an Android app) as well as running it via a local webserver (at localhost:3030
), and in both cases the cross-domain requests work completely fine.
I'm at a loss for what to do now. Is there something else I can alert to get more information about the error? (Maybe it's other headers causing the issue?)