How to run an Android application from command line!

Source: Deep Learning on Medium


Go to the profile of Garima Nishad
Image Courtesy: Google

This article outlines the usage of popular tools used for Android development on the command line, in particular, Android (Android), Android Debug Bridge (adb) and how they can be utilized to build an Android application project and how to install and debug an Android app using the command line.

Requirements:

(1) Install the latest Java Development Kit (JDK) from Oracle.

(2) Installed Android SDK. If you have not done so yet, you can download the Android SDK here: developer.android.com/sdk

So let’s begin :

  • Open the terminal.
  • To start the process, first, display a list of available Android device(s) that are currently configured, copy this command:

<your android sdk directory>/tools/android list devices

Then you’ll see something like this :

and then you’ll have your list of devices:

Now you can monitor your “ANDROID EMULATOR”

  • <your android sdk directory>/tools/emulator -avd <name of avd>

If you don’t know the name of your avd yet, don’t worry! You can find it out using this command:

  • <your android sdk directory>/tools/android list avd

You’ll see something like:

So the “Name “ part would be used to replace <name of avd> in the command line:

  • <your android sdk directory>/tools/emulator -avd <name of avd>

I’m assuming here that you’ve already created your android project.

Now let’s compile the android project:

Before you compile your project, you must be connected to the internet in order for the gradle wrapper script to download the appropriate gradle software components. Once ready, to compile your Android project, navigate to your project directory on your command line (change directory), and do this:

For Mac or Linux-

  • ./gradlew build ()

For Windows:

  • gradlew.bat build

Now upload a specified apk file from your computer to an emulator/device.

  • <your android sdk directory>/platform-tools/adb install -r <your APK file>

If this doesn’t work then push the apk using adb:

  • adb push <your android app directory>/build/outputs/apk/debug/app-debug.apk /data/local/tmp/org.tensorflow.lite.examples.classification

Then start launcher:

  • adb shell am start -n “org.tensorflow.lite.examples.classification/org.tensorflow.lite.examples.classification.ClassifierActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

The logcat command of adb is used to display system information of a running Android OS (whether device or emulator). This is remarkably helpful to find out what is happening to an application or a device.

  • <your android sdk directory>/platform-tools/adb logcat

and there you have it, your own working android application from the command line!

Screaming with joy yet?