Android Apps and Local Servers


#1

I’ve seen this question a few times, but no times recently, and it was never answered satisfactorily. Maybe somebody has figured this out.

I’ve got an app, it builds and deploys to my Android phone just fine, but it doesn’t pull documents from the localhost database in development. I’ve spent two days on this with absolutely nothing as a result – I’m as certain as I can be that my router does not have client isolation by default. If it helps, I’m running Ubuntu 16.04.

Interestingly, I don’t even see the login button that I’ve got in there, which does show up in the Desktop browser.

Any help would be appreciated.


#2

How do you run it on your device? meteor run ios-device?
Can you connect with Chrome to the device to see the console log?


#3

I run it with meteor run android-device.

Are you asking me to try connecting to the localhost from Chrome on my phone? Because I have tried that, and it does not work.


#4

ok

Yes this: https://guide.meteor.com/mobile.html#remote-debugging-android That should work, are you connected with a usb cable to the device?


#5

Yes, I am connected with a USB cable, and have the phone and the computer connected to the same WiFi. After entering location.reload in the DevTools console, the output is as follows:

deviceready has not fired after 5 seconds.
Channel not fired: onDOMContentLoaded

ddp-client.js?hash=2750240…:942 GET http://xxx.xxx.x.xxx:3000/sockjs/info?cb=ll89n7cptj net::ERR_CONNECTION_TIMED_OUT


#6

That’s not correct, you should be able to open that url:

http://localhost:3000/sockjs/info?cb=ll89n7cptj

And then see something like:

{"websocket":true,"origins":["*:*"],"cookie_needed":false,"entropy":123456}

Do you see more non resolving paths in the network tab in the Chrome debugger?
Did you do any custom configuration?


#7

Well, the only configuration I did was on the initial run command, like so:

meteor run android-device --mobile-server=localhost:3000

That’s what got me that last error in the developer console; running the command without the --mobile-server option didn’t give me the ddp-client error at all. It’s strange and I’m finding nothing helpful in the documentation.


#8

That makes sense! For locally running you don’t need to set mobile-server. It’s also the right way to do it according to the guide:

Here is the mobile-server option mentioned: https://guide.meteor.com/mobile.html#connecting-to-the-server

If you run help on the command line:

$ meteor help run
Usage: meteor run [target..] [options]
[....]
Options:
  [...]
  --mobile-server  Location where mobile builds connect to the Meteor server.
                   Defaults to your local IP and the port that the Meteor
                   server binds to. Can include a URL scheme (for
                   example, --mobile-server=https://example.com:443).
 [...]

You can see it needs to be a full path, not just the server name.

Be aware that for iOS it needs to be a https url. For Android I am not sure, anyway it’s good behavior to run on https in production.

But for your issue: Not it’s not required to supply that mobile-settings option at all, Meteor will default to local by itself.

If you want to do it the right one would normally be:

meteor run android-device --mobile-server=http://localhost:3000


#9

sure, but I tried it with the http:// protocol prefix too, and it still didn’t poll the database. And as you said, it should be defaulting to the correct local server anyways.


#10

That is strange! So what errors do you get now? Do you have a simple example which doesn’t work?

Btw. it seems also without http it should work: https://github.com/meteor/meteor/issues/3698#issuecomment-204667996 but not sure on that. Also not sure how it would detect http or https so I would just include the full url.

And does this return a connected status for you:

Meteor.status()

You can run that in the chrome console.


#11

That’s the thing – I only get the first two errors if i don’t specify the --mobile-server, ie:

deviceready has not fired after 5 seconds.
Channel not fired: onDOMContentLoaded

Which is basically telling me what I already know.

I’ll attempt to grab a status when I’m back on my development machine. Thanks for the help so far!


#12

So just don’t specify the server. Not needed on local. No error is a good thing right? :slight_smile:

When you have a more clear example on your original issue:

but it doesn’t pull documents from the localhost database in development

Please post it here so we can take a look at the relevant pieces.


#13

What I meant is: it doesn’t matter if I specify the server or not, I still don’t get my view components populating from the database.

As I said, I’ll post again when I’m at my dev machine.