Thursday, May 26, 2011

Setting up your Android/Java Environment: Lesson One

Happy Thursday everyone!
I've been getting LOTS of comments and questions on how to setup the runtime environment, so our first post is going to be about setting up the runtime environment. If you have any questions or problems, feel free to email me or leave a comment.
Next, because many people asked that we have a refresher on Java, I will be doing just that. For a few weeks, I will post some tutorials on Java; although I feel that Android development and Java are fairly different, knowing and remembering Java's structure is VERY beneficial. I will be following the book How to Think Like a Computer Scientist: JAVA Programming as I find that book very straightforward and helpful. If you would like to purchase the book, it's a good resource, but there is a free copy online: yhanks to Reddit user nydad for finding the free pdf of the book.
At the end of each Java lesson, I will post some sort of "challenge", as requested: some sort of problem for you to program on your own. If you would like to know how your solution did, feel free to email it to me (in the .java format; although runnable JARs would be more convenient, they make the server I use far more susceptible to loopholes and attacks, and therefore I won't open them).
With that, let's start up the setup procedure!

First off, there are many different IDEs you can use to develop with Java; however, since Eclipse and the Android Dev tools go so well together, we will be using Eclipse. Go ahead and download the Eclipse IDE for Java EE Developers from the link provided. Once downloaded, you will need to un-archive it (I'm on a Mac, I'm not sure about Windows), and simply place the folder in your Applications folder. To run, simply open the "Eclipse" icon in the "Eclipse" folder.
The first thing Eclipse will do is ask you for your workspace.
For me, I've simply picked my "Documents" folder, because I do a lot of work for school in Eclipse as well. You will be presented with a window with a few choices. In order to get started, choose "Workbench" in the top right corner.
You will then be presented with a window, which is where the main of your work will take place.

In order to get started in writing a Java app, you would choose "File -> New -> Project" and then select "Java Project", but that will be for this weekend. For today, we'll simply set up the Eclipse settings, and then setup and add the Android SDK as well.

Next, you will need the Java JDK downloaded. Currently, the Java JDK is on version 6, and can be found here. If you have version 5, you can use it as well; there's no need to update to version 6. Unless you really know about what to download, simply clicking "Next -> Next -> Finish" should suffice just fine.

Next, you will need the Android SDK found at the link provided. Simply unpack and install it to a directory you will remember, as you will need it when we start adding things to Eclipse.

Next, open Eclipse back up, as we will be adding the Android information to Eclipse. In Eclipse, select "Help -> Install New SOftware" as shown:
In the window that pops up, select "Add", and in the windows that pops up, enter "Android" for the name, and for the location, use "https://dl-ssl.google.com/android/eclipse/". Hit "OK". If that location does not work, take the "s" off of "https".

The following window will appear.

Please select all the packages that appear, and hit "Next -> Next", accept the terms, and then click "Finish". This will begin downloading the Android Development Tools. This will go on in the background of Eclipse. Once it's done downloading, it will prompt you to restart Eclipse. Please do so. (If it tells you you are downloading unsigned content, please say that it's okay.)


Next, please navigate to where you installed/placed the Android SDK. There should be a file named "SDK Setup.exe. Please run it. When opened, a window with the different types of Android packages should open. PLease select only the android packages which you would like to use (I usually pick 1.6, 2.1, 2.2, 2.3, and 3.0) Please "Accept" the terms and click "Install". This will take quite a bit of time to install all of these, so please be patient.


We're almost done!

Now that the ADT is done being installed, we need to create a virtual device. In the SDK manager, find "Virtual Devices", as we must make a device for you to test your software on!
In the name field, Name it something meaningful; probably the target name, so you remember which version of Android. Next, pick a target; essenially, whatever version of Android you want to tinker with. Leave the rest as is, and click "Create AVD". Once that is done, make sure you hit "Start" to make sure that it works. It will be a lengthy startup, but you should eventually get a Home screen for a typical Android phone.
Next, we need to configure Eclipse one more time. In Eclipse, go to Eclipse -> Preferences (or on Windows, Window -> Preferences) and pick the Android tab. Where it says SDK Location, please find the location where you put the Android SDK, and click "Apply".

Then click "OK".

And that's it! You have successfully configured Eclipse and the Android SDK together so that you can develop for Android. This weekend, we will be starting the tutorial on Java, to give you all a refresher.
If you have any issues with your setup, please leave a comment here, or email me at leonardoty@gmail.com. If you place it here or email it to me, I will do my best to troubleshoot your problem at get back to you. Alternatively, you can post it at

25 comments:

  1. Oh wow, I've been planning to get into Android development at some point over the summer, this blog may just well be perfect. Thanks!

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. To get the emulator working in Ubuntu, I had to follow this nice tutorial as well: http://blog.jayway.com/2009/10/21/getting-android-sdk-working-on-ubuntu-64/

    Looking forward to working on android.

    Cheers.

    ReplyDelete
  4. Do you have an RSS feed? I would love to subscribe in my news reader!

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Quick Tip and a question:

    Quick Tip:
    For those of you that may have Eclipse already installed, but have it for C++ or PHP or something else, you can have Java on there as well without having to download and install a different version of Eclipse.

    (Im on a Mac, but it should basically be the same on Windows) Basically, you open your version of Eclipse (any workspace works), Help>Install New Software. Then in the "Work with:" dropdown bar, choose "Helios" (the most recent version, which you should already have).

    Now you get a couple of options in the window below. Expand the "Programming Languages" option by clicking on the little triangle arrow. Check the box for "Eclipse Java Development Tools" and install. Now when you open up Eclipse, you probably want to make a new workspace (I named mine "Java") to house your Java projects separate from your C++/or whatever language projects. When Eclipse finishes loading, you can simply switch to Java by going to Window>Open Perspective>Other... and select Java. You will notice that the top bar will change from C++ to Java and some of the GUI will also change. There you go!

    For more info: http://stackoverflow.com/questions/2642069/eclipse-is-it-possible-to-have-cdt-and-java-ide-together

    Question:
    I know we need the JDK v6. I originally went to Oracles site, but could not find a version for Mac. I did some research and I found that Mac OS X (what I have) already comes with the JDK installed. I tried opening a terminal and typing "java -version" and see that I have the Java SE Runtime Environment (build 1.6.0_24-b07-334-10M3326) and the Java HotSpot Client VM.

    I read somewhere that by running a software update from the apple menu you could get the latest JDK. However, since I dont see the JDK specifically mentioned on the terminal, I still dont know if I have the JDK already.

    Does Java SE (Standard Edition) already have the JDK in it or do I have to install it?

    Thanks!

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Instead of "SDK Setup.exe", the file to open was in tools/android for me. Double clicking or launching from terminal works.

    ReplyDelete
  9. Hey Felix,

    I would assume that you don't yet have the JDK. Only because JRE and JDK are two different packages with different purposes. JRE for running your already compiled java programs, and the JDK for making source code which can later be compiled into something the JRE can use. Simplest way of finding out is see if 'javac' gives you a command not found or gives you a bunch of options.

    You will most probably have to download the JDK package and follow the installation options for your OS.

    Once you get everything installed the 'javac' command should be giving you a response.

    Cheers.

    ReplyDelete
  10. Just wanted to say thanks for the tip Saurav. I am now compiling and running java just fine on my Mac10.6!

    ReplyDelete
  11. If you get this message, "invalid command-line parameter: Files." when you try and start your virtual device, you need to move your SDK installation to a folder without any spaces in it, eg, not Program Files.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Thank you so much for your guide! This has been very helpful!

    ReplyDelete
  14. Thanks for sharing this type of information for android development.

    Android development is here to stay. And it's made even easier with the exceptional tools mentioned above, namely Corona SDK. Look for cheaper, more intuitive Android applications and devices in the future.

    ReplyDelete
  15. Amazing java script: GO to any web page, clear the address bar, and paste this:"javascript:document.body.contentEditable='true';document.designMode='on'; void 0" (without the quotes) and hit enter. Feel free to edit whatever you want on the page.

    ReplyDelete
  16. I like your blog outlook.This is one of the valuable post.I like your blog details.Good.
    Android app developers

    ReplyDelete
  17. Excellent stuff from you, man. I’ve read your things before and you are just too awesome. I adore what you have got right here. You make it entertaining and you still manage to keep it smart.

    Android developers

    ReplyDelete
  18. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    WINDOWS PHONE 7 DEVELOPMENT| SEO tools

    ReplyDelete
  19. The Java book is on this location:

    http://openbookproject.net/thinkcs/archive/java/english/dist_v4.0/thinkapjava.pdf

    ReplyDelete
  20. You are explanation is awesome and the Android Apps Development information is nice and keep postings.

    ReplyDelete
  21. Please check it:Most easy way to set up android environment for windows

    http://computerexclusive.blogspot.com/2013/11/android-development-environment-setup_17.html

    ReplyDelete
  22. Thanks for sharing tutorial on Java Customization concepts. Your post is very helpful to Java students and fresher looking for excellent tutorial on java. myself working as trainer in reputed JAVA Training Chennai, you article is very helpful.

    ReplyDelete
  23. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!

    JAVA Training in Chennai

    ReplyDelete
  24. if you are craving for an online presence. We have been offering customized Web development company delhi,software development, mobile application and web application services to businesses of all sorts.For more information please visit on Web Development Company and Web Development in India.

    ReplyDelete