How to Run an Android Application from the Command Line!
Last Updated on July 20, 2023 by Editorial Team
Author(s): Garima Nishad
Originally published on Towards AI.
Android, Programming
Have you ever got tired of having low RAM on your PC while using IDE?
or?Have you ever wanted to run a single script and run all of your applications in a go?
If the answer is βYesβ to any of those questions then youβre in the right place! You wonβt need any IDE to run your android application anymore! No more hanging up!
Isnβt that amazing? Letβs get into it then!
This article outlines the usage of popular tools used for Android development on the command line, in particular, 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:
- Install the latest Java Development Kit (JDK) from Oracle.
- Install the latest Android SDK. If you have not done so yet, you can download the Android SDK on Android Developers.
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 working android application from the command line!
Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.
Published via Towards AI