Set up a Java environment for Cordova/phonegap development on Ubuntu 12.04
Installing Cordova (Phonegap)
I added these to my ~/.bashrc
PATH=$PATH:/path/to/where/i/put/it/adt-bundle-linux-x86-20130522/sdk/platform-tools:/path/to/where/i/put/it/adt-bundle-linux-x86-20130522/sdk/tools ANDROID_BIN= /path/to/where/i/put/it/adt-bundle-linux-x86-20130522/sdk/platforms/android-17
I'm not saying this is the best way but it worked for me
./create /path/to/new/directory com.yourproject yourproject
You must not use spaces in the last part (even within quotes), because then it fails like this:
jorgen@battle:~/workspace/android/phonegap-2.8.0/lib/android$ ./bin/create /home/jorgen/workspace/android/testproject2 net.jorgenmodin.test "A name with spaces in it" An unexpected error occurred: "$ANDROID_BIN" create project --target $TARGET --path "$PROJECT_PATH" --package $PACKAGE --activity $ACTIVITY &>/dev/null exited with 1 Deleting project...
Install Java 7
Download it from Sun, follow the instructions from the highest rated answer on this page: installation - How do I install Oracle Java JDK 7? - Ask Ubuntu
But add the following:
sudo update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk1.7.0/bin/jar" 1
I had no jar command, if you already have one it may work however the fastjar program did not understand phonegap's switches so it is not an option.
Install the JDK
The emulators never launched, with no explanation.
You can start an emulator from the command line, by going inside the sdk directory and inside tools and then run
./emulator -avd <emulatorname>
That informed that there was a segmentation fault, and core dumped
By adding the verbose switch, these were the last two lines:
emulator: Initializing hardware OpenGLES emulation support Segmentation fault (core dumped)
So, googling for that leads to this page:
Which says to do like this
mv tools/lib/libOpenglRender.so tools/lib/libOpenglRender.so.xxx
Which then made verything work.
Self-signing an apk
If you want to try out your apk on different devices, without connecting them with a USB chord to the development computer, you need to sign the apk. Otherwise it will simply just fail to install. This page shows how to self sign an apk:
I used the option
keytool -genkeypair -keystore keystorename -storepass keystorepassword -keyalg RSA \ -validity $((25 * 365)) -alias keyalias -keysize 2048 \ -dname "CN=J Random Hacker, O=HackerCo, L=Anytown, ST=Anystate, C=US"
jarsigner -verbose -keystore keystorename apkfilename keyalias
keytool and jarsigner commands were already installed on the laptop (different from my workstation), it may be different for you. On my workstation I had to do
sudo update-alternatives --install "/usr/bin/jarsigner" "jar" "/usr/lib/jvm/jdk1.7.0/bin/jarsigner" 1
In Eclipse there is support for signing in the Android Tools context menu.