How to launch an Android app from the command prompt | October 19th, 2010
We want to pretty much do what Eclipse does when we build&run an Android app:
Compile, Build Package, Uninstall package, Run the app in the emulator/device
function run_emulator {
package="com.package.name" # replace this with your package name
class=$1
ant debug && \
adb -e uninstall $package && \
adb -e install -r bin/$class-debug.apk && \
adb -e shell am start -a android.intent.action.MAIN \
-n $package/.$class
}
If you want the same thing to run on a device:
function run_device {
package="com.package.name" # replace this with your package name
class=$1
ant debug && \
adb -d uninstall $package && \
adb -d install -r bin/$class-debug.apk && \
adb -d shell am start -a android.intent.action.MAIN \
-n $package/.$class
}
Add these two functions to your shell profile. It works with Bash and I haven’t tried with other shells.
Here is how to run the app:
$ cd /path/to/your/android_app_root $ run_emulator ClassName # replace this with the main activity class name
If you deal with different package names you can also specify the package name as a command line argument.
Happy Android Coding!
