Saturday, 6 November 2010

Google Maps in Android (emulator)

In order to get google maps in your apps and so build location-based services, your must register with Google, and include a key that they'll provide against a MD5 string that you get from your own system. If you're like me, just developing and debugging without deploying your apps, you'll need one key called "debug.store", another one will be used to comercially deploy your apps.

I've done that using Eclipse, so here it goes. Locate your .android folder, on Ubuntu/Linux, that's in ~/.android, it's a hidden file, (hence the dot .android, type ls -a for hidden files), on Windows 7, its location is at C:\Users\\.android. This file contains a digital certificate that is going to be used to create the MD5 string. You need Keytool in Eclipse, Eclipse is the "does it all for you" and is getting really powerful so if you're concerned with efficiency in producing code, Eclipse is the main thing.
To install keytool, once again go to the Help menu, install new software (in Helios), click add for a new repository, add http://keytool.sourceforge.net/update, (check http://keytool.sourceforge.net/), then follow the usual procedure to install plugins in Eclipse.

Once installed, they'll be a menu called keystore, choose open keystore, browse to the "debug.store" in the .android folder, and type "android" as password. It took me a while to find the password ... In the lower part of eclipse, where the console usually is, select the keytool tab if it's not already, double click on "androiddebugkey", the certificate should open and the MD5 Fingerprint displayed. Copy it and go to Maps API Key Signup - http://code.google.com/android/add-ons/google-apis/maps-api-signup.html, you need a valid Google account for that, accept their terms and conditions, and paste the key where it says so. It should give you back the key to insert in your code. That's in your project folder in Eclipse, open main.xml located in the res then layout folder and where it says apiKey, insert it. Now theoretically, it should display a Google map in your app. And it does!

Your main.xml should look like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<com.google.android.maps.MapView
android:id="@+id/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="Your API Key" />
</LinearLayout>

Eclipse + Android

Android SDK Intallation Log

In order to run the Android SDK - Software Development Kit and start writing code in Eclipse, you must download the SDK at http://developer.android.com/sdk/index.html, android-sdk_r07-linux_x86.tgz for linux, i386, there's no 64 bit version as it seems. The file must be extracted from the .tgz file and placed in its due location, in my case that's /usr/local/bin/. Again, as with the Java JDK, add the location of the Android folder to the path.
Next, from within Eclipse, mine is Eclipse Helios, you must install the ADT plugin for Eclipse, so choose the help menu, then install new software, click then the add button to add a repository, something like Android plugin for the name and https://dl-ssl.google.com/android/eclipse/ for the location. Select the check box next to Developers tools and start with the installation.
Once it's installed, it needs to be configured. Select Window->Preferences then Android from the left panel. Update the location of your Android folder by clicking Browse. It should now know where to locate all the necessary class files to start developing.
Last thing to do, select the help menu, go to Android SDK and AVD Manager, then click on the available packages to get the Google APIs that you might need. Select the ones that are relevant for your work, in my case, I'll stick for now to the latest version of Google API, i.e. version 8, you should that in order to run on older versions of Android, your app should be tested on the previous APIs, and thus downloaded now. I haven't got to that part since I'm not comercialising my software (for now), so I'll skip for later on, I feel nonetheless, that it wont't be easy to make it work on all the previous platforms.
After installing the API, all should be ready now to code your first Android app.

Nota: To run it under Linux 64bit, you need to install the ia32-libs package using apt-get:
apt-get install ia32-libs (Ubuntu 10.10LTS 64bit)

Friday, 5 November 2010

Eclipse Installation Log

I've downloaded eclipse-jee-helios-SR1-linux-gtk-x86_64.tar.gz from the Eclipse website, that is Eclipse Helios last version up to date.
As I forgot to install the Java Devolopment Kit (JDK), I pointed to Sun's website (pardon me, Oracle's brand new machine) and got JDK 6 Update 22 (Java SE Development Kit 6u22), after chosing Linux 64 bits, which lead to jdk-6u22-linux-x64.bin.
I've moved the binary file to /usr/local/bin/, and eclipse's as well. I'm running Ubuntu 10.04 LTS on Virtual Box.
As sudo, I've run the Java script, that's ./jdk-6u22-linux-x64.bin at the prompt. It started to decompress and finally created everything in a folder called jdk1.60.22. Next step the always tricky part of setting the path to the Java home in the PATH. So sudo (whatever editor you use, I might Vim), that's sudo vim ~/.bashrc (bashrc is a hidden file in your home directory and configure the shell environment, you need to type ls -a in order to see it). At the end of the file, I've inserted:
export JAVA_HOME=/usr/local/bin/jdk1.6.0_22
export PATH=$JAVA_HOME/bin:$PATH

When I type at the prompt, echo $PATH the JAVA_HOME is appended. I took me a while.
Problem: Eclipse wouldn't launch, it was giving a error saying no Java virtual machine found. After some digging, (online digging?!) I've come up to this site http://stackoverflow.com/questions/142357/what-are-the-best-jvm-settings-for-eclipse/1409590#1409590 and this one at http://stackoverflow.com/questions/142357/what-are-the-best-jvm-settings-for-eclipse/3275659#3275659. Following instructions, I altered a file called Eclipse.ini in the Eclipse folder. I just added two lines:
-vm
/usr/local/bin/jdk1.6.0_22/bin/java
the whole file looks like this:
-startup
plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.1.R36x_v20100810
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vm
/usr/local/bin/jdk1.6.0_22/bin/java
-vmargs
-Dosgi.requiredJavaVersion=1.5
-XX:MaxPermSize=256m
-Xms40m
-Xmx384m

Just added a launcher on my desktop and that it, it works. It sounds simple but almost got the whole afternoon. I'm actually suffering from time management problems, that means I STRESS!
Ok, next step, installing Android platform.