Connecting android app with the server


#1

Please help!

Can someone please post a list of the steps that have to be done to connect android app (made with the meteor build tool) with the server (not local).

Till now i developed the app on the server (Ubuntu) and build the .apk there also. I assume there is some configuration that have be to done like in the settings-mobile.json file and perhaps adding some server info as parameters in the build command. But i really cant find any “straight-forward” explanation in the web.

Thank you in advance!!
Meteor Rules!!


#2

Hello Krest,

did u find informations about that ? im at the same point and i can’t really find good infos on the web, there is not too much about that in the meteor doc.

thx


#3

When you compile the mobile app you have to set --server

When you call --run-android it takes care of it for you - but for builds, you have to specify it at compile time. You can even specify the IP address of your local machine for testing (e.g http://192.168.0.2:3000)

I would love to know if there is a way to change the server on the fly on the client, @sashko is that possible?


#4

1) Add the mobile platforms (e.g. android) to the app that you want to build for:
meteor add-platform android

2) Create the bundle with this command:
meteor build ../bundle --server "SERVER-ADDRESS":"PORT"
e.g.
meteor build ../bundle --server 5.189.163.221:3301

Some more info : http://stackoverflow.com/questions/27617869/generate-apk-file-for-meteor-app

So now the app contains the server information to which it will connect.
You can take the .apk file that was created with the build command (somewhere in the bundle folder), and install it on android device or emulator (BlueStack is a good one for windows)
When the app will start i think it will show you a message that connection with the server failed
or something like this.

Now for the Server Side ->
Unfortunately i didn’t make the app to the production phase
So i didn’t ran the bundle file on the server.
It was in the “raw” meteor format.

3) So to make the Server to listen for the Mobile apps i used this commands:
MONGO_URL=mongodb://127.0.0.1:27017/"dbname"
meteor --mobile-server "SERVER-ADDRESS":"PORT" --port "PORT"
e.g.
MONGO_URL=mongodb://127.0.0.1:27017/meteor
meteor --mobile-server 5.189.163.221:3301 --port 3301

P.S.
I assume that if you build the app with the following command, perhaps the bundle file on the server also will work. Never tried it though.

meteor build ../bundle --server 5.189.163.221:3301 --mobile-server 5.189.163.221:3301 --port 3301

Hope it will help you.

Please if you find more information, share it.


#5

Few useful server variables that should be configured before starting the app on server.

export MONGO_URL='mongodb://username:userpass@www.domainname.com:27017/mongoDbName'

export ROOT_URL='http://localhost'

export PORT="PORTNUM" (e.g. PORT='3000')

Also there is a MAIL_URL if you are going to send mails from your app.
Ask your Host company for the correct input
Should be something like this.

export MAIL_URL='smtp://mailaccountname:mailaccountpass@abc1.mail.domainname.com:123'


#6

That would be truly awesome.


#7

Hello Krestt123,

First i owe u a big “thank” for ur explanation, according to what u wrote i’ve been able to connect my server and the apk ! I used this command :

meteor build ../bundle --server 51.255.167.129:80 --verbose

I let the port by default here and i added the server info (user and password) info in my mup.js file, i didn’t have to specify for my database assuming mup uses the same than connecting to the server so here what i have :

      ROOT_URL: 'http://www.legoutdessaisons.com',
      MONGO_URL: 'mongodb://127.0.0.1:27017/legoutdessaisons'

i didn’t have to use this next command (maybe because info are already in the mup.js file ???) :

meteor --mobile-server "ipserver":"port" --port "portnumber"

Also i notice this time that my build command made two apk’s one in the /bundle folder that i specified in my first command and one other in .meteor/local/cordova-build/platforms/android/build/outputs/apk !

Why two apks ? im wondering…

Anyway thank u for ur help and i will add more infos as soon i found some…

Yoann