The Android Studio Story 2: When the life begins.

So In the first part we have met our new friend Android Studio and knew a little bit about it. In this post I am going to share with you the installation and running the first basic project. I have used Android Studio in Windows 7 and Xubuntu 12, and apart from some issues I have faced [Which I will discuss later in the post] the installation and setup is pretty easy. For Mac, I have heard from friends that it works seamlessly in their systems, and found no-problems working on it. Apart from that I haven’t had mac machine to face and test many problems.

So First, lets prepare our Machines to install the android studio. Which as of now requires JDK installed. If you have android SDK installed it will be surplus to you, but IMO android studio comes with it’s own bundle of SDK which will be installed when android studio installed itself.

To get started, download android studio from here. Like eclipse’s beloved ADT bundle, Android Studio is available in all three major Desktop OSes. And After downloading installation is pretty straight forward, in case it’s not Google has documented the instruction nicely.  And following them will make your android studio installed properly.

Android studio requires the path of proper JDK installation to work with, the launcher script of android studio is written to find out the path it self, which is JavaHomePath/bin/java, where JavaHomePath is the home directory where your java installed. If you are aware about such path exists on your system, copy it to a new environmental variable called JAVA_HOME before you start android studio for the first time.

So far this story is pretty much known to those enthusiasts who have already downloaded android studio and working with it. And you can find the issue and it’s solution in stackoverflow, google groups, many blogs and nearly every android development forums. But there was one problem I faced and couldn’t find proper solution online, Finding a solution myself lead me to the place where setting up new environmental variable became optional when the launching script can not find a proper java path installed, and still you can start working with android studio.

Ubuntu does not have Oracle’s JDK pre-installed and even they don’t have an easy way to install it directly, and generally they use OpenJDK as the replacement of Oracle’s JDK. Google has developed Android Studio such a way that OpenJDK is not advised to use [It gives some error message when Android Studio finds OpenJDK is default JDK in system and we can not start Android Studio.

There are some workarounds exist. We have to download Oracle’s JDK installer and add it into `usr` or set newly downloaded Java’s path as any system variable. But to do that we must have fully functional Admin access of the system, and not all users are lucky to have that.

Thankfully Android Studio’s running script is an sh file that we can study and edit as per our need. When I studied the script I found that Android Studio just needs a path from where it can pick some essential java tools so it can work smoothly. The purpose of having a system variable to have such path handy and available all the time. But this is not the only case. We can refer to an external path which script can access with all permission needed and Android Studio can work around this path as well.

And a Modified Script is born.

The addition on the original script are as follows.

1. At first it tries to read something from path.config file if it exists. If not found it will look for other system variable for proper Java path.

refer lines 36 to 40 on above gist to see how it works.

2. If none of the Java path are proper [Esp it happens when Open JDK is found] It usually throws error and exits. I have modified a script around it so user can be able to insert any proper custom path for JDK and after check this path will be written in path.config file stated on step 1.

refer lines 126 to 134 to see how it works.

[Note: If you can not see the gist properly, you can always go to the original gist here]

This is it. Now after passing any possible hurdles, the android Studio is up and running. If you know how to setup android sdk and create a project in eclipse, the procedure for the same action in Android Studio doesn’t differ a bit. If you don’t know head to android developers’ official training guide to make yourselves familiar for that.

If you are familiar to android and it’s development with eclipse I suggest you to start reading Mark Ellison’s recent blogpost about the new gradle build system in Styling Android. Please note that this series is not completed, it’s taking shape. I request you to read it because he’s diving deep into Gradle which we are to cover next in this series, only the part we need to create a normal app of our need.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s