Fork me on GitHub

WhatsApp Clone with Meteor and Ionic 2 CLI

Ionic 3 Version (Last Update: 2017-06-15)

Android testing

Note: If you skipped ahead to this section, click here to download a zip of the tutorial at this point.

Testing on Android

In this step we're going to test our application on Android using Cordova.

Firt we will need to install Gradle system wide, becuase the latest Cordova framework cannot use Gradle from Android Studio. On Arch Linux just install the gradle package.

Then we're going to install the Android SDK. I suggest you to install Android Studio and use the SDK Manager to download it. On Arch Linux just install android-studio form AUR.

The SDK Manager will install the Android SDK into ~/Android/Sdk/.

NOTE: it seems the SDK Manager doesn't fetch all the necessary tools which Cordova needs, so I had to download sdk-tools-linux-3859397.zip and uncompress it into ~/Android/Sdk/.

Now we need to export the ANDROID_HOME environment variable and add all the Android SDK tools binaries to our PATH. On Linux it is as simple as adding:

export ANDROID_HOME=~/Android/Sdk/
export PATH=${PATH}:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin

to ~/.bashrc and ~/.bash_profile. Obviously you will have to log out and log in again in order to update the PATH.

Now attach your Android smartphone to your computer using the USB cable, enable USB debug and check if it recognizes it:

$ adb devices

Otherwise you can create a virtual device using AVD Manager.

Now we can add the Android platform to Cordova:

$ cordova platform add android

We will have to fix the failed-to-restore-cordova-plugin-statusbar issue:

11.2 Fix failed-to-restore-cordova-plugin-statusbar issue package.json
36
37
38
39
40
41
42
 
76
77
78
79
    "cordova-plugin-device": "^1.1.4",
    "cordova-plugin-ionic-webview": "^1.1.15",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-statusbar": "https://github.com/apache/cordova-plugin-statusbar.git",
    "cordova-plugin-whitelist": "^1.3.1",
    "ionic-angular": "3.7.1",
    "ionic-plugin-keyboard": "^2.2.1",
...some lines skipped...
      "android"
    ]
  }
}

Next time we will run cordova platform add android it will overwrite our package.json and we will have to re-edit it.

Finally we can launch the application on the smartphone:

$ cordova run android

Our application seems to work properly, but as soon as we will try to log in we will find that something's wrong. To discover what we will first have to learn how to debug a mobile application with an embedded WebView. Let's open Chromium in our desktop, then the Console.

Now follow the istructions to inspect the WebView.

In the Console you will find the following error:

GET http://localhost:3000/sockjs/info?cb=l8rjuale0e net::ERR_CONNECTION_REFUSED

If you open the Network tab you will also notice a couple of failed requests to http://localhost:3000/sockjs/info.

Since our DDP server doesn't run on the smartphone we will have to tell the Meteor Client where to find it:

11.3 Add meteor-client config meteor-client.config.json
1
2
3
4
5
6
7
8
{
  "runtime": {
    "DDP_DEFAULT_CONNECTION_URL": "http://meteor.linuxsystems.it:3000"
  },
  "import": [
 
  ]
}

You will have to change meteor.linuxsystems.it with your own IP or at least put an entry for it into your /etc/hosts file.

11.4 Update meteor-client package.json
15
16
17
18
19
20
21
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve",
    "meteor-client:bundle": "meteor-client bundle -s api -c meteor-client.config.json"
  },
  "dependencies": {
    "@angular/common": "4.4.3",

Now let's rebuild the meteor-client:

$ npm run meteor-client:bundle

Next time we will run cordova run android everything will work as expected.