Prep work
Before attempting to deploy our shiny new app, we need the following three things:
- Java JDK
- Android Studio
- Updated Android SDK tools
For details on how to implement the above requirements, visit the Cordova documentation. Make sure everything is installed and setup properly according to the documentation.
Connect the device
When it comes to deploying the app to an actual device, sometimes simply enable USB debugging and Developer Mode on the device might still throw some errors. It will most likely indicate that there is no device found. This is where we need to setup the command-line tool Android Debug Bridge. It should be installed already during the pre-deployment preparation. To find out where it’s installed, go to [ SDK Manager > Appearance & Behavior > System Settings > Android SDK ] and look for Android SDK Location.
We need to look for the executable file of Android Debug Bridge adb.exe
. In my case, it’s in
C:\Users\Ren\AppData\Local\Android\Sdk\platform-tools\adb.exe
For Windows users, setting its location to PATH of environment variables will allow launching via terminal, which is very convenient.
Now it’s time to connect the device.
In this case, we’ll be connecting via WIFI but first we need to connect via USB cable and run:
adb devices
It should show a list of devices attached.
Next, Set the target device to listen for a TCP/IP connection on port 5555:
adb tcpip 5555
We can now disconnect the USB cable and connect to the device by its IP address:
adb connect device_ip_address
The device should now be connected and if running adb devices
you should see:
List of devices attached
device_ip_address:5555 device
To terminate the server, simply run adb kill-server
.
Refer to Android Debug Bridge for details.
Deploy
We can now deploy our app by running the desired build:
Debug build
ionic cordova run android --device
Production build
ionic cordova run android --prod
Or just create a build
ionic cordova build android --prod
For further customization of a build, refer to CLI Commands for run and build.
The app should now be installed and runnning on the device.