Android app doesn't fetch data when built with a signing key

  • 1
  • Question
  • Updated 3 years ago
If I build my android app with a key, it installs fine on the phone but doesn't fetch any data. The app works just fine if I compile it without a key.

Can someone tell me what is going here?

Thank you.
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
I created the key using this page: http://docs.build.phonegap.com/en_US/...
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You must have changed something else, too. The signing key has no effect on such functionality (if you meant "retrieving data from a web service using XHR" with the phrase "fetch data").
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
What can I possibly change?

I do 2 builts back to back. One without the signing key and one with the key. When I download and install .apk for the one built with the key, app is dummy. No data fetching (no data retrieval from the web service). Empty page. However when I install the one that's been built without a key, the app works fine...

Please share any insights/ideas you might have.
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
Testing the .apk in emulator directly fiddler opened.

There doesn't seem to be any outgoing requests at all.
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
Almost all night spent and no luck. Something is definitely up but can't figure out what.

I tried compiling without a signing key in the cloud and then signing and aligning the apk myself in the local; then installed in emulator and it worked fine. Though google play refused uploading by saying the apk was built in debug mode and for security reasons it must be in release mode.

I'm stuck on this.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Hi Tyler,
I still doubt that this has anything to do with the signing key.
Usually, if data can't be read from an external server (within the app) although it all works in an emulator or browser, it's a whitelisting issue.

Things to note, though:
- you mentioned an 'empty screen'. That doesn't clearly indicate that data aren't fetched. It could well be the presentation not functioning. So, it's important to determine exactly where in your code the error takes place.
If your XHR function gets called and runs, but no data are returned, you should have a close look at whitelisting. If the ajax function is never called/activated, then it's obvious that data will never be retrieved. In that case your script logic is buggy.
- if you signed your app and PGB returns a "[appname]-debug.apk, you know that something is wrong. Most likely, you have debug switched on in your PGB settings.
- you shouldn't try and upload something to Google Play if it has never worked properly in your test device. You don't want to upset users who download and install your app, do you?
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
Hey Petra,

Thanks again.

It can't be white-listing issue because I select "No key selected" for android then build the app and install it in my phone, it just works fine. Without touching anything else, I just change "No key selected" to my signing key in the dropdown for android, build the app and install it in my phone (or emulator) and no data fetch occurs.

Of course no debugging nor hydration is ever enabled for the app.
For whitelisting I have <access origin="*" /> in the config.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
1. Do you get a "[appname]-release.apk" returned from PGB after building with signature?
2. For what PGB version are you building? If cli-5.x.x, did you include the whitelist plugin?
3. Why does "no data fetch occur"? Is your XHR invoked at all? Do you get any javascript errors? Does your web service receive any request?
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
1- Yes I get [appname].release.apk from the build
2- Phonegap-version is v3.7.1
3- No requests received by the web server at all
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
1. OK
2. There is no PGB 3.7.1
3. OK, but is your XHR function invoked, then? Do you get any javascript errors? Is your script logic already interrupted before you even reach the XHR function?
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
Apologies about the version, I meant 3.7.0.

I use jquery ajax for data fetching and the function (in which I call $.ajax) gets called with all expected parameters but hits fail handler directly. Fail handler function is being passed the following error object:

error: {
"readyState": 4,
"status": 404,
"statusText": "error"
}


But in the network tab, I don't see any logged outgoing network activity/requests at all.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
That sounds like a CORS problem. Does this happen from a real device (I hope not) or from the emulator (which I assume)?
Just for test purposes, you could set the Access-Control-Allow-Origin header server-side to "*" in order to prevent an access denial during preflight.
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
If it's a CORS problem why it doesn't happen when I compile the app without a signing key?

It happens both in a real device and emulator.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
That's a legitimate question.
I don't know. I was just thinking out loud, because (a) I have never seen this kind of behaviour reported here before, and (b) I can't actually see what's happening and what's been coded.

I have 20+ apps, all using webservices, ajax and jQueryMobile, and none of them shows this strange 'feature' you have here. I am just trying to 'shoot in the dark', thinking loudly and trying to come up with what could be worth checking.
As said, I can't think of a single logical reason why the certificate could make any difference for the XHR. :-(
Photo of Amir

Amir

  • 8261 Posts
  • 263 Reply Likes
@tyler

Did you install a self-signed SSL cert on the server? If so that could be the reason.

During debug it will pass any bad SSL cert or self-signed one without problem. Once signed, android:debuggable will be set to false hence only valid SSL are accepted for remote transaction.

Try switch to normal HTTP (80) and see if that is the case.

Thanks
(Edited)
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
Thanks. It isn't self signed ssl in the server side.
I already tried switching to regular http it didn't fix the problem.

Again just to add, no problem in the ios app. When compiled without a signing key, no problem for android either.
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
Obviously something is going on with app signing.

How can I locally sign my app and still have a releasable apk?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Have you tried to access a completely different server/domain with a signed app, in order to see if it depends on the remote web service?

I ask, because hundreds of developers manage to make ajax calls with signed apps, so something must be different in your case.
(Edited)
Photo of Tyler Armstrong

Tyler Armstrong

  • 12 Posts
  • 0 Reply Likes
That's one thing I haven't tried. Thanks for pointing out Petra.

I'll test that case and let you guys know.
Photo of Reyes Pinto Moreno

Reyes Pinto Moreno

  • 1 Post
  • 0 Reply Likes
Hi... any news about this issue? Currently I am facing the same problem!!!