Saturday, April 23, 2011

Building Android Projects from Command Line

I have been spending a lot of time with Android and I am making really good advantages with my app :) even though it is taking a lot of weekends and nights. It is difficult to make progress when you have a full time job that sometimes looks like a 2 full time jobs.

I think I noticed that sometimes using eclipse to build your project and deploy it into the emulator takes a lot of time and I already talk about how slow the Android Emulator is and some ways to it make less slow. One of them is to use command line to create your apk and then install it into the emulator or device.

First, you need to create the build.xml file so you can use ant. To do this you might need to update your root directory project to do that you can execute:

@chambras:~/AndroidWorkSpace/my-app$ android update project -p .
Added file ./build.xml

Once the build file is added you can build your app in debug mode. Just open the command line and write:
ant debug
This will create your debug apk inside your project bin/ folder and looks like [your_project_name]-debug.apk
The next step is to install the apk in the emulator and to do that you just need to do this:

adb install [path_to_your_apk].apk

or if you have multiple emulators or devices running you can execute adb devices so you will see all the devices connected and emulators running and then you can execute:

adb -s emulator [emulatorid] install [path_to_your_apk].apk
If you want to install it in your device:

adb -d install [path_to_your_apk].apk
In order to make this process fast I would recommend adding the platform-tools/ and tools/ folders to your PATH if you are using windows. If you are using Ubuntu or Mac you can do this:

sudo ln -s /path/to/android/tools/android /usr/bin/android
sudo ln -s /path/to/android/platform-tools/adb /usr/bin/adb
These will create symbolic links to those tools so you can execute them form anywhere. Here is more information about building android projects and here on how to use your device.

Happy coding :)

1 comment:

  1. hello sir
    I have basic project of helloworld in android. how to debug and run that project and make a apk file. please send me step of run the android project with example.