Server doesn't work when installed onto phone

  • 1
  • Question
  • Updated 3 years ago
Using 000webhost to save php and database files. Works when running app with phonegap desktop but once installed onto phone with apk nothing happens with the server. Does anyone have any ideas on to why this is?
Photo of Patrick Cummins

Patrick Cummins

  • 12 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Patrick,
Welcome. Apparently, you are very new to Cordova/Phonegap

Phonegap is not a webserver or a webbrowser.

This FAQ should also help.
Top Mistakes by Developers new to Cordova/Phonegap

Jesse
Photo of Patrick Cummins

Patrick Cummins

  • 12 Posts
  • 0 Reply Likes
Thanks for your reply. I am indeed very new to phonegap. This is my first interaction with it. I thought if I used an ajax call to the url of the php file hosted on 000webhost and sent a datastring of the variables that it would work. I just don't see how it works perfectly fine when I run the app using the phonegap app from app store on my phone and not when I build to my phone. It is still calling the same url isn't it? Am I missing something small here? Sorry if it is a stupid question.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
I think Jesse misunderstood your question. He may have thought that you installed a server on your phone.

Is this correct?:
- You built an app using PGB
- Your app contains ajax calls with requests to a PHP script hosted at a hosting provider called '000webhost'.
- You get request replies as expected when using on Phonegap Desktop, but nothing when testing on a real device.

If so, your whitelisting is not OK. This can have many causes:
- config not found, read and parsed due to wrong directory structure
- whitelist plugin wrong or not included
- whitelist rules not as expected
- CSP blocking requests
- timing issue (not waiting for deviceready)
- phonegap.js/cordova.js not referenced
Photo of Patrick Cummins

Patrick Cummins

  • 12 Posts
  • 0 Reply Likes
Thanks for the quick reply.

Yes that is all true.
But would testing it on the phonegap android app on my phone not be testing it on a real device or does it take that as something else?

I will have a look into the whitelisting when I get home from work.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Patrick,
Yes, you've been fooled too. I'm trying to get phonegap to fix this issue, but it is not easy.

Here is my canned response:

I need to blog this, so i don't have to repeat this answer again and again.

You cannot use Phonegap Desktop App with Phonegap Build.

Phonegap Desktop App uses Phonegap CLI, so if you want to use Phonegap Desktop App you need to stay with Phonegap CLI.

If you want to use Phonegap Build, then forget what you have done and start over _OR_ make Minor modifications to move Phonegap Desktop App to Phonegap Build. To be clear, the difference is minor, but enough to keep tripping you.

Also, you will not be able to use Phonegap Developer App as that is meant to work with Phonegap Desktop App. You cannot use either CLI or Build with Developer App.

FWIW: I've been trying to get Phonegap to fix this. Here is the report on the issue.

Let me know what you want to do.

Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
The Phonegap app requires a different directory structure. Also, whitelisting is automatically inserted when using that Phonegap app.
So, testing on a Phonegap app is rather testing on a pre-assembled preview tool and quite different from working with your app on a real device. You can't substitute the former for the latter.

It's a common issue reported here at the forum. In fact, whitelisting issues (and wrong directory structures) are the single most frequently questions asked here.
Photo of Patrick Cummins

Patrick Cummins

  • 12 Posts
  • 0 Reply Likes
Sorry If I sound stupid.

So you are saying that if I build an app using Phonegap Desktop App it won't work when I upload it to the website Phonegap Build and download the apk onto my phone?

I was just using the Phonegap desktop app to test my app while I went along.

Are you saying if I move my config and index.html file around when uploading to phonegap build website it should work?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
I said that multiple causes are possible. The most frequent problems that we see here are:
- wrong directory structure (config is not found)
- old plugins from the pgb repo instead of plugins from npm
- missing cordova.js reference
- wrong witelist rules
- timing issues (deviceready)

Without seeing the zip file that you uploaded, I can't tell which issues play a role in your situation.
(And yes, many developers asking such questions have used the Phonegap app, expecting that everything will work after building at PGB. That's not a sign of being stupid....Phonegap just doesn't make the differences sufficiently clear)
Photo of Patrick Cummins

Patrick Cummins

  • 12 Posts
  • 0 Reply Likes
Thanks again for the reply.

I will try out all these different scenarios tonight and see how I go.

I will inform you of how I get on.

Thanks again for your help
Photo of Patrick Cummins

Patrick Cummins

  • 12 Posts
  • 0 Reply Likes
Also FYI my config file is on the root directory and my index file is inside www/ directory
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
No not correct. Petra has the same suggestions you will find in the link a gave you above.
Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
I suggest you:
- move config to your /www
- adjust the paths inside config
- zip up the CONTENTS of /www (not the directory itself)

As a result, config and index are both in the root of your zip.
Photo of Patrick Cummins

Patrick Cummins

  • 12 Posts
  • 0 Reply Likes
Sorry I'm second guessing myself now. I'm not sure what directory structure I have. I have the structure of what ever the default one you get when downloading phonegap first time.

It is more than likely the config and index are inside the root of the WWW/ directory If I can remember correctly. But I zip the application folder which contains the folders for plugins, WWW and so on. That would mean config and index are not at the root.

I will try just zipping the WWW directory later.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
But I zip the application folder which contains the folders for plugins, WWW and so on.
You shouldn't.
PGB will not build correctly if you include directories like /hooks, /platforms and /plugins.
Perhaps this would be a great time to read the Getting Started section of the PGB Docs.
Photo of Patrick Cummins

Patrick Cummins

  • 12 Posts
  • 0 Reply Likes
Thanks for your reply. Yes I will start by looking through the docs.
I was working off watching youtube videos and copying how they uploaded to Phonegap build. It worked perfectly until I put in the posts to 000webhost. I will go back to the drawing board
Photo of Patrick Cummins

Patrick Cummins

  • 12 Posts
  • 0 Reply Likes
Thanks for your help, when I moved the config file it worked perfectly for me.
Photo of Benjamin Železnik

Benjamin Železnik

  • 2 Posts
  • 0 Reply Likes
Hello all,

I'm very new to PhoneGap and PhoneGap Build and have similar problem as Patrick had.

I've made a very simple app which just pulls some data from public accessible site. It works flawlessly on PhoneGap, even on phone connected to PhoneGap server on PC.
Having this, I uploaded everything to GitHub on root directory and instructed PhoneGap Build to make an apk. Running it on Android phone, just static html content is shown, but nothing what is supposed to be updated online.

May I ask somebody to take look at my index.html file and explain me where I fail, please?

Thank you!
zelezni
Photo of Benjamin Železnik

Benjamin Železnik

  • 2 Posts
  • 0 Reply Likes
In addition, I discovered that if I check Hydration before the build, it works. Without it, it's like described above.