Tags:
I have just recently bought the HTC Hero phone with the Android operating system. In my life I have had a whole lot of PDAs from Apple Newton MessagePads to Psions to WinCE (unbelievable that Microsoft's crap stinks like on the first day even after ten years of evolution) to Zaurus to - now - Android. Although I was sceptical I must admit that I'm loving most everything that Google does so it's the perfect choice. And although Android is not entirely free Google at least offers the SDK for nuts. And although I had no clear intention of developing a certain application I was missing I still wanted to try at least a "Hello World". So this article is supposed to get you started with Android application development using Debian.
What's so special about it?
You are probably wondering why I am writing about preparing a development environment on Debian. Isn't it all explained at the SDK page? Well, yes, it is. But still the preparations are far from being straight-forward. Reasons:
-
you must use
SUNOracle Java although your system may run the free GCJ Java compiler. (As much as I endorse free alternatives it's pretty pointless to use anything else here.) - Eclipse 3.4 on Debian is buggy and nobody seems to be able to package 3.5
- Eclipse has a few rendering problems unless a magical environment variable is set
To spare you the trouble I had to go through I wrote this little article. Make sure you have a little time and a good internet connection. Let's go.
SUN Java
Android applicaitons are basically Java programs (plus optional C++ components). So first you need to install SUN's Java development kit (JDK) and make sure the default Java installation on your system is SUN's. To be able to install it you will have to add "non-free" to your APT sources. Check your /etc/apt/sources.list that it looks similar to:
deb http://ftp.de.debian.org/debian/ sid main contrib non-free
You may have "stable" or "lenny" instead of "sid" here. That should work, too.
Then install the necessary Debian packages:
$> apt-get update $> apt-get install sun-java6-jdk sun-java6-jre
If you are using a 64-bit environment like amd64 then you need the 32-bit compatibility package, too:
$> apt-get install ia32-libs
If possible just remove a possible installation of GCJ:
$> apt-get remove gcj-jdk
Now to make sure that your default Java compiler is SUN's please run
$> update-alternatives --config javac
$> update-alternatives --config java
Make sure it points to something like /usr/lib/jvm/java-6-sun/bin/java…
And on a fresh Debian installation I had an annoying pitfall. Any attempt to obtain a network connection failed with "java.net.ConnectException: Network is unreachable". If you don't use IPv6 then editing /etc/sysctl.d/bindv6only.conf and setting "net.ipv6.bindv6only = 0" and afterwards running "/etc/init.d/procps restart" there helped me fix that.
Eclipse
Although you can develop Android applications with any IDE you are recommended to use Eclipse for which Google offers a working plugin. (I haven't tried EasyEclipse - perhaps it does what I did manually.) Eclipse is somewhat standard among Java developers although it's bloated and non-trivial to install and run. The latest version in Debian (as the time of writing) is 3.4. And it has trouble with installation additional software. The current version of Eclipse is 3.5 but apparently the Eclipse developers did not make it easy for package maintainers to create distribution packages for it. So the best bet is basically to install Eclipse 3.5 into /opt on your disk manually.
Go to the Eclipse home page and from the confusing list of software to download just pick the "Eclipse classic" (version 3.5.1 as the time of writing this) either Linux 32-bit or Linux 64-bit depending on your system. It's somewhat around unbelievable 160 MB.
Unpack the downloaded archive to /opt:
$> tar -C /opt -xzf /path/to/downloaded/eclipse-SDK-3.5.1-linux-gtk.tar.gz
Fix the permissions:
$> chown -R root:root /opt/eclipse
Create a shell script somewhere that sets the necessary environment variables and launches Eclipse. The script should contain:
#!/bin/bash export MOZILLA_FIVE_HOME="/usr/lib/firefox/" export ECLIPSE_HOME="/opt/eclipse" export GDK_NATIVE_WINDOWS=1 /opt/eclipse/eclipse
Android SDK
Now it's time to download Google's actual SDK to develop Android applications. Get the SDK from the download page. Choose a location where you want to install the SDK. I prefer using my home directory:
$> cd
$> tar xzf /path/to/downloaded/android-sdk_r04-linux_86.tgz
You should add the tools directory of the Android SDK to your shell path by adding this line to your shells startup script (e.g. ~/.bashrc):
export PATH=${PATH}:${HOME}/android-sdk-linux_86/tools
Android/Eclipse plugin
Now start Eclipse using the shell script your created earlier. With any luck you are now in Eclipse and ready to install the Android plugin.
Click the "Help" menu and choose "Install new software". In the "Work with" field add this URL:
http://download.eclipse.org/releases/galileo/
Apparently Eclipse does not come with it's own URL pre-configured. After Eclipse is finished loading the available components from that URL click open the the "Web, XML and Java EE Development" section and choose the "WST Server Adapters" item.
Again add another URL in the "Work with" field of the "Install new software" dialog and enter this URL:
http://dl-ssl.google.com/android/eclipse/
And click on "Add" and install the shown plugin.
Finally tell Eclipse where your Android SDK is located by clicking the "Windows" menu then choose "Preferences". Then in the "Android" section set up your "SDK Location" to where you unpackaged your Android SDK (e.g. ~/android-sdk-linux_86).
Prepare the virtual Android device
The Android SDK comes with an emulator for Android devices which really makes it nice to test your application. Just launch the "android" program:
$> android
A configuration window should come up. The problem here is that this program tries to fetch the additional files using HTTPS but it only worked for HTTP here. So go to the "Settings" section and select the checkbox before "Force https:// ... sources to be fetched using http://...".
Then go to the "Available Packages", select all (unless you know which Android version you will be developing for) and install them. This may take a few eternities and blow up your Android DSK directory to over 900 MB of data (cough). I hope you have a good internet connection.
Now create a virtual machine for your Android emulator. Go to "Virtual Devices" and create a machine. I choose Android 1.5 here because that's what is currently running on my HTC Hero. You should be able to click on "Start" then and see an emulation of an Android device. Give it a while to boot and you will hopefully see a simulated Android device on your desktop that you can work with.
Create a project
Now that everything is set up you are ready to create a project for your new application. Instead of copying stuff from the Android developers' page I suggest you start reading there.
Feedback please
I'm an Android development noob. So suggestions are very welcome!
17 Comments
Nice Work.
Submitted by DebianUser (not verified) on
Work perfectly on my Debian Lenny, Thanks Alot !
use update-java-alternatives
Submitted by James Lewismoss (not verified) on
Greeetings!
Submitted by dalareo (not verified) on
Thanx a lot. It works perfect under debian 64 bit (testint) now!!!
Bug with latest Eclipse - got "cannot connect to keystore"
Submitted by Andrew (not verified) on
When installing the WST plugin - missing certificates that come with the Java SDK
are stored into /etc/ssl/certs/java/cacerts
* Hit problem - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=258301
* Had to install java certificates from squeeze
http://packages.qa.debian.org/c/ca-certificates-java.html
sudo dpkg -i /scratch/download/ca-certificates_20090814_all.deb
sudo dpkg -i /scratch/download/ca-certificates-java_20100412_all.deb
Thank You Very Much
Submitted by David (not verified) on
Thank You very much for your hard and diligent work at putting this together.
I have been fighting the lenny java eclipse combo for a few days now. I was ready to give up and go back to the wicked windows, until I came accross this site.
My android SDK in eclipse is now working thats to this page.
Thanks for great
Submitted by Michel (not verified) on
Thanks for great article
this can help me, its work
Great job
Submitted by Gianluca (not verified) on
Worked fine on squeeze/sid + Eclipse SDK Version: 3.6.0
Thank You very much!
GJC should be GCJ
Submitted by Lucius (not verified) on
Hi!
By mistake, I guess, you wrote GJC instead GCJ twice.
Regards
Right. Thanks for the
Submitted by Christoph Haas on
Right. Thanks for the correction. Fixed. :)
Ubuntu+eclipse+android
Submitted by Ankitg (not verified) on
HI,
I have installed every thing on my ubuntu system successfully but to locate sdk i need to click on windows->preferences
->android.
here is the problem i cant see the last part(android).
I have tried uninstalling and reinstalling every thing from scratch.
do reply i need your help
Pages