Command-line Android

We often use Eclipse for Android programming. Of-course creating an Android project is simple and easy for a beginner and advance user using Eclipse. Eclipse creates a file hierarchy needed for an Android project. Also building and running an apk is even simpler. But for those who don’t want to switch to GUI or who want to stick to the terminal for Android programming, read on ..

Creating an Android project

Provided you have an android-sdk in your path.

Syntax

android create project \
    --name project-name \
    --target target-API \
    --path path-to-your-project \
    --package package-name \
    --activity name-of-your-main-activity

Example

android create project \
    --name HelloAndroid \
    --target android-15 \
    --path . \
    --package com.hello.android \
    --activity MainActivity

Building an apk

Building an apk is also simple, type

android update project --path . --target android-15 --subprojects

which will create a necessary build.xml file required for ant, and run

ant debug

this will create an unsigned-debug apk inside the bin directory of your project.

Testing your app

Starting emulator

Start the AVD using,

Syntax

emulator -avd name-of-your-avd

Example

emulator -avd test

If you want to list all your virtual disks, type

android list avd

Installing an apk

To install an apk, visit your project directory and run

Syntax

adb install path-to-your-apk

Example

adb install bin/com.hello.android.MainActivity.apk

Launching your app

To test your app, type

Syntax

adb shell am start -a android.intent.action.MAIN -n your-package-name/.your-main-activity-name

Example

adb shell am start -a android.intent.action.MAIN -n com.hello.android/.MainActivity