Thursday, February 16, 2012

Android Development Environment on Ubuntu

First things first. To app programming in Android we need an working environment. There are many possibilities to configure this environment but in this entry I'm going to explain the one that I use.

Operating System:

Ubuntu 10.10 Maverick Meerkat
Programming Environment: Eclipse Indigo + ADT Plug-In
Latest Version Android SDK

I must say that there are new available updates of this OS, but I decided to use 10.10 because  Unity desktop (or Gnome Shell) are too slow, so working with them could become a nightmare.


First: Prepare the OS

You need to install the SUN ORACLE JDK.
  1. Download JDK from ORACLE download page.
  2. Unzip the packet: #tar -xvzf jdk7u2.tar.g
  3. Move created folder to /usr/local. You can also take advantage in this point to shortening the name, for example jdk7.2
  4. Now, you can tell the OS that uses this JDK with the following comands:
  5. #update-alternatives --install
    "/usr/bin/java" "java"
    "/usr/local/jdk7.2/bin/java" 1
  6. #update-alternatives --set java
    /usr/local/jdk1.7/bin/java
  7. Then you'll need to create the JAVA_HOME environment variable and update the PATH. To do this you can edit /etc/profile and add:
  8. export JAVA_HOME=/usr/local/jdk7.2
  9. export PATH=$JAVA_HOME/bin:$PATH
  10. Execute #source /etc/profile to load the environment variable
  11. Now JDK is installed. To check it you can try #java -version and the system should show infromation of the instaled version of Java.
This first part has not been too much complicated and the upcoming ones will be even more simple.

ECLIPSE AND ANDROID SDK INSTALLATION
 
Once JDK is installed we can move to the next point. Installing Eclipse programmer framework. At the moment I'm writing, latest version of this framework is Indigo. We can download it from the official site, getting the eclipse-java-indigo-SR1-linux-gtk.tar.gz file. Unzip this file in our personal folder (for example).
Once unziped you can go to the Ubuntu Menu,  System->Preferences->Main Menu. Here you can add new element to the programming menu and select the icon you will find into the unziped Eclipse folder.
The Android Developer page recommends to modify eclipse.ini to set the configuration like this:


-XX:MaxPermSize=256m
-Xms128m
-Xmx512m

It refers to the amount of memory to use by the Java Virtual Machine.

Now we must download the Android SDK. This contains libraries and utilities to connect the devices  to the computer. Unzip it and that's time to install ADT plug-in for Eclipse. This plug-in allow the communication between Eclipse and Android SDK. To install it you can go to Help->Install new software, in the Eclipse Menu. In the appearing dialog you must type the following direction:


https://dl-ssl.google.com/android/eclipse/


Typing address in ADT plug-in installation.




Once installation is done, you have to restart Eclipse and then you must configure ADT plug-in to link the SDK Android folder you unziped in the previous step (go to Window->Preferences->Android). With this plug-in you can download all Android Versions to develop. The majority of android devices uses version 2.2.1 or later. You must know that 3.x versions are only for tablets devices, and version 4.x are for both tablets and mobile devices, but, for the time being, it works only on the brand new Samsung Galaxy Nexus.

It seems that our development environment begins to be valid, but we still have one small thing to do: we need our system detects our device to be able to install apps and debbug it from Eclipse.

In Windows we have only to install drivers, but in Linux it's different. First we have to plug device to computer using USB.


MAKE UBUNTU DETECT ANDROID DEVICE TO DEVELOPMENT

First of all, we need to know device Vendor Id: We must use lsusb command and we'll see something like this, depending on the device brand:


Bus 002 Device 005: ID 18d1:4e22 Google Inc.

We have to look at first 4 numbers of ID.
Then, we should go to /etc/udev/rules.d and we'll see what are the names of .rules files (they should begin with a number, like 70 in my case).
In this case we would create a file named 70-android.rules writing on it the following:

SUBSYSTEMS=="usb", SYSFS{idVendor}=="xxxx", MODE="0666"

where xxxx would be the first 4 numbers of ID, that is 18d1 in my particular case.
Be careful with double quotes, because if there aren't appropiate it won't work. o be sure, the better is to write yourself, don't copy-paste.

Now you must unplug device and go to platform-tools folder into Android SDK unziped folder. There must be an executable named adb. From there you can execute the folowing commands:
sudo restart udev
./adb kill-server
./adb
start-server
./adb devices
Where we should see :


List of devices attached
34346DD882B200EC
device

If there are question marks means it has not worked.


note 1:(adb is located in
androidSDK/platform-tools
if we want to use adb like a regular command we must insert it in the PATH:


export
PATH=${PATH}:/home/TU_USUARIO/android-sdk/platform-tools
export
PATH=${PATH}:/home/TU_USUARIO/android-sdk/tools


and then we will be able to use adb much more comfortably
)



note 2: If any time trying to install an app to device from Eclipse you have the following error:


Unable to open sync
connection!

You can take two ways:
  1. restart device
  2. check out debugging mode and check in then
Obviously second way is faster.

Well, following these simple instructions taken mainly from the android developer website, you can get your Ubuntu ready to start developing android applications in a comfortable way. In this website you can find guides and samples to start, and in this blog we will start developing on following entries. See you soon!






No comments:

Post a Comment