Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, June 20, 2011

Android development in Linux/Windows

I am currently working on developing an Android app and thought of sharing the basics of Android app development. I develop in Linux. It should be the same in Windows.

First, you need the Eclipse IDE. You actually can develop for Android without it but it's a lot easier with Eclipse. Installation of the eclipse IDE in Linux (In Windows, it isn't a problem) from the eclipse site might lead to complications later on with regard to location of Java and running from the terminal etc. So, I suggest you install it from the synaptic package manager. To install the Eclipse IDE and get it working, you will need Java installed in your computer. Installation of Java in Windows is a piece of cake with ready made exe files and other Windows crap. Java installation in Linux can get a little hard if you are new to it. You can read another post of mine which explains it in detail. Now, assuming you have got Java and eclipse installed in your computer, let's move further.

Download the Android SDK for Android development from their official site.

Tip#1 for Windows: Download the recommended installer and run it. This installer checks if Java is installed in your computer. A bug here is even if you have, they don't let you proceed saying that JDK is not installed. This wasted a lot of my time but I found a way around this by clicking Back and then Next again. All of a sudden, they are able to detect JDK (windows is lame, it's high time you get that, folks).

After extracting the Android SDK directory in a location of your choice, follow the instructions on the site. It also includes the installation of the ADT plugin of Eclipse.

Tip#2 for Windows: While setting the preferences for the ADT plugin in Eclipse, you won't be able to give the android sdk location because they will give an error saying adb.exe is not present. All you have to is got the Android SDK directory and run the SDK manager and install platform-tools. This directory once installed will contain the adb.exe file and you can now set the preferences of the ADT plugin.

Tip#3 for Windows: When you try installing any of the packages that need to be installed like platform documentation etc., you might get an error saying unzip failed, nothing installed. This happens because you don't have Administrator privileges (if you have extracted eclipse in C:\) You can prevent this from happening by running eclipse by right clicking eclipse.exe and Run As Administrator. But, you might have to do this whenever you want to install anything. So, I suggest moving the eclipse folder to the D or some other drive.

Now, you would have downloaded atleast one platform to run your android apps. I had installed the API Level 12 platform which kept crashing. I suggest installing the API Level 8 platform. Safe and woks well (Look at the timestamp of this post. If you are reading this a long time later, then API Level 12 must be working properly now).

I hope you have now got Eclipse with ADT working now. Any doubts, please post them as comments and I'll be happy to answer them. Go ahead and write your Hello World! application. Happy coding :)

P.S: Wait for my next post which will incllude sample codes and tips ;)

Saturday, June 11, 2011

Setting up Java in Linux

Setting up Java in Linux can be a real pain when you are an Ubuntu noob. It took me quite some time (nearly a day to be precise) to get it working. After a lot of purges, fresh installs and reboots, its successfully installed. I thought of sharing with you the goldmine "Java installation in Linux made easy" :P

I had initially installed Java from the official site by Oracle but it always gave me a lot of errors whenever I opened Eclipse, saying "Java 6 was not installed". I am sure there were many ways to work around it with a lot of commands etc. But, c'mon let's face it, we are Ubuntu noobs. So, I had to purge the whole installation and cleaned the entire system of Java before starting all over again. This time I used the method mentioned below and it worked.

Open the terminal and install sun java with the command

sudo apt-get install sun-java6-jdk sun-java6-jre

This should the whole sun java installation process. To be on the safer side, after this installation, open Synaptic Package Manager (System>Administrator>Synaptic Package Manager) and search for sun-java6-bin, sun-java6-jre, sun-java6-jdk and sun-java6-plugin. If they are already marked as installed, well and good, otherwise install them. They say the jdk does include the jre and you don't have to install both of them. But, I installed both.

JDK and JRE will mostly be installed at /usr/lib/jvm/java-6-sun-1.6.0.24. Ubuntu will create a symbolic link to java and javac at /usr/bin/java and /usr/bin/javac for easier access.

Next, we have to create a symbolic link to show where Java is installed in the system. This can be done with the following commands.

sudo ln -s /usr/lib/jvm/java-6-sun-1.6.0.24/bin/java /usr/bin/java
sudo ln -s /usr/lib/jvm/java-6-sun-1.6.0.24/bin/javac /usr/bin/javac

Lastly, you have to set the JAVA_HOME variable. This can be done by opening the .bashrc file in the home directory as superuser and editing by including this line at the end.


export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.24"

Finally, you can check if Java is installed by typing the following command in the terminal


java -version

If it returns the version number of Java installed in your system, then Bingo! You have got Java successfully installed in your system.

Now, you can install your JDK SE or EE bundles from the Oracle site.