sábado, 9 de mayo de 2015

How to install the Android Stand-alone SDK Tools on debian linux, and run your first app

I'm using a brand new install of Debian Jessie to start developing my first android apps. I haven't found a good how-to on installing the Android Stand-alone SDK Tools on debian. I had to tweak the ones I've found.

The first thing I did was to download the file android-sdk_r24.2-linux.tgz from:


Once you've got the file, extract it's contents, cd to the directory containing the extracted tool files and run android update sdk --no-ui like so:

$ tar -xvf android-sdk_r24.2-linux.tgz
$ cd android-sdk-linux/tools
$ ./android update sdk --no-ui

Make sure you have an internet connection when doing this. The command will download and install the command-line sdk to develop android apps. Note that this will probably take a while.

You must have java installed in order to start developing for android using the command line tools. Don't worry if you didn't install java before installing the android sdk. In debian, you may use synaptic, apt-get, or aptitude to install java. On synaptic I just had to install default-jdk

If you prefer aptitude, do (as root)

# aptitude update
# aptitude install default-jdk

Or using apt-get

# apt-get update
# apt-get install default jdk

Make sure you have the required repositories to install the package.

The official development tutorial for android provides steps for creating a first test project. But I couldn't get it to work on debian the way it was laid out on their page. One thing I had to do differently was to create the project with gradlew support, like this:

$ tools/android create project --target android-16 \
--name MyFirstApp --path workspace/MyFirstApp \
--activity MyActivity \
--package com.example.myfirstapp -g -v 0.11.+

The options in red are missing from the official android dev tutorial.

After that, you will be able to compile your 'Hello World' app with:

$ ./gradlew assembleDebug

To run your android project without an android emulator, you'll have to use your android device. First, make sure you enable USB debugging on your device, connect it to your PC via USB, and make sure your device is listed under the lsusb output. My device shows up like this:

Bus 002 Device 004: ID 0fce:5172 Sony Ericsson Mobile Communications AB

Then just load your recently compiled project as you normaly would, with

$ adb install app/build/outputs/MyFirstApp-debug.apk

And just take it from there. Happy android programming!

NOTE: If you're having trouble with "command not found" errors, make sure to either cd to the directory where the commands live in your extracted files, or add the appropriate paths to your PATH environment variable.