Click here to Skip to main content
Click here to Skip to main content

Starting Android development on Windows

, 1 Aug 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Set up your own environment for Android development on Windows, from the ground up and everything in between.

Introduction

Given the fact you are reading this article, chances are quite high you already know what an android is. Possibly. In science fiction novels and films, an android is essentially a robot with anthropomorphic traits. Remember C-3PO, from StarWars? What about Data, from StarTrek? Don't get distracted now, please! For the course of this writing, we'll do our best to keep it real. Let's talk about Android™ (with a capital "A" and a trademark symbol), by Google Inc.

The Android robot

Android is the open-source mobile operating system based on the Linux kernel and used for smartphones, tablets and wearables. Hundreds of millions of devices are running on Android right now. It's just about the perfect time, then, to bring your developer skills into the friendly green robot's realm. Mobile developers in general are in high demand nowadays. What would be the best platform to apply one's talent on, other than this which has consistently owned over 50% of the mobile market share ever since barely a few years after its appearance?

The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

Being already here, maybe all these aren't exactly fresh news to you, anyway. Put it like this: as a developer, it's pretty much a sure thing you have the will and the wisdom to look into starting to learn and conquer this new technology. Most probably, you came here just for that. So, how to start? One way or the other, you have been set in the right path. Just keep reading.

Background

To best follow and take the most fruitful advantage of the information shared herein, please consider that it has been assumed you have previous experience as a developer of some sort. This paper will introduce you to the technology and guide you through the first steps required to configure your own development environment for Android. Nothing more.

Applications targeting the Android platform are written in Java™, for the most part. There is also C and C++ for native development and smoother hardware integration, as well as for improved performance on advanced graphics. Other options are available too, like: C#, HTML5+CSS3 and whatnot. Teaching any of these languages and their related technologies is way out of the scope of this article.

Windows™ and Android

Why Windows for Android applications development? Ambivalent answer: why not? Truth is, you can develop Android applications on any operating system you want. Well, as long as it runs Java and provides the minimum required hardware capabilities. Windows, Mac and Linux are all three supported. So, the question remains: why Windows?

There are so many technologies, tools, platforms and languages available to contemporary software developers and programmers, that it's certainly impossible to find someone in the industry who at the same time: works on a single platform, speaks a single programming dialect and is worth enough their salt to be paid for their bacon, coffee and beers. The world is harsh; the race is tough. Starting with Android doesn't mean to abandon any previous source of income, joy, enlightenment or whatever.

If you are a .NET developer, for instance, and you work systematically on projects targeting the Microsoft .NET Framework, WPF and the whole breed of compilers and tools that come with them, then the most logic step to explore Android would be to do it precisely from the comfort of your already known and deary environment. It would allow you to have Windows Phone development tools also right there at the reach of a hand, for example. This very same logic applies to Mac and Linux too. Maybe you are an iOS developer. Perhaps you are more into absolute freedom. The final note here is that you can ultimately choose the platform of your own preference.

For the ideas presented henceforth, Windows has been used for illustration purposes.

Android and Java

Before you can build the next worldwide successful Android app that will make you filthy-rich and famous, you will need something called the Android SDK. This acronym should be already familiar to you for its ubiquity throughout the whole tech world; it stands for Software Development Kit (sometimes also called Standard Development Kit). The Android SDK provides the command line utilities, build systems, emulators... and a plethora of other handy stuff on which the humble developer relies to craft applications for such platform. This toolset, in turn, depends on something called the Java Development Kit (JDK). It is crystal-clear, then, what are the first and second steps to this walk.

Step #1: Install the JDK

Get ahold of a copy of the JDK installer from its provider's website. Make sure to get version 6 or later. At the time of this writing, the latest publicly available and recommended stable version is 7, update 65. Remember that actual version numbers for Java are 1.6, 1.7 and so forth, plus the update number. So, when someone says Java 7, they effectively mean major version 1.7 without specifying any particular update number. You can also use Java 8, although it is not particularly recommended yet for Android development.

Beware that there is also a packaged version of Java called the Java Runtime Environment (JRE). It is no good for Android development. It is actually needed, but not sufficient. Any JDK installer installs its corresponding JRE too, so there is no need to install them separately.

You can get the JDK installer from the following link:
http://www.oracle.com/technetwork/java/javase/downloads/index.html

A word of advice: even if you are on a 64 bits OS, you are advised to install a 32 bits version of the JDK instead (the ones that contain i586 in their file name, sometimes also x86). This is so, such that some tools in the Android SDK can find Java without hassle out of the box right after their installation. If for some reason you insist on using the 64 bits version, then you might need to perform additional configuration steps. This also applies if you want to use Java 8 or later. See below.

Step #2: Install the Android SDK

The Android SDK is readily available in various forms, often referred to as bundles or packages. It is distributed by Google from the developer.android.com website and is for anyone to download and install. There is also the so called stand-alone version as well, which is a distribution bearing only the minimum set of tools needed to kick-start the configuration of your development environment. Faced with the various options, which one should you choose? First get to know them, then make your mind with an informed decision.

A valuable hint to always remember is that, regardless of the approach taken, the SDK is essentially XCOPY deployed. It means that all the files, dependencies and tools are under a single root directory (except for the special case of the JDK, of course). There are no irksome registry keys to set, no brittle environment variables to keep track of, no mystical drivers to go hunt for. It also means one could share the same SDK configuration across several computers or move it around using a removable USB device, and things like that. This shall be taken with a grain of salt, though, specially on Windows (more on this later), but overall that's a driving philosophy.

The Eclipse ADT Bundle

Perhaps the most widely known distribution form of the Android SDK amongst developers is the Android Development Tools for Eclipse (Eclipse ADT, for short). There are basically two scenarios in which you would install Eclipse ADT. If you already have a set up copy of the Eclipse IDE, you just install and configure ADT as you would any other plugin, plus the stand-alone Android SDK.

The other option is to download a full package which contains a copy of Eclipse with the ADT plugin already installed, plus a readily usable copy of the Android SDK with every bit of the software required to start developing right away (simply download, unpack and run). This latter approach is the fasted method to just get to it and start developing an application without unnecessary delays. This is also provided by Google, under the name of ADT Bundle.

Either one you choose, remember you should have Java properly installed beforehand.

The full package containing the Eclipse IDE with the ADT Plugin and the Android SDK can be downloaded at:
http://developer.android.com/sdk/index.html#download-bundle-button

For the ADT Plugin alone (to be added to an existing installation of the Eclipse IDE), go to:
http://developer.android.com/sdk/installing/installing-adt.html#Download

Stand-alone Android SDK

In the case you already had Eclipse up and running and you just want to give it some droid-fu skills, or if you intend to develop Android applications with some other IDE, you would have to install the stand-alone version of the Android SDK. This is the most lightweight form in which you will find the SDK: stripped of any additional paraphernalia used to ease or completely skip the initial configuration effort. For this reason, it is sometimes also referred to as the SDK starter package. For Windows, there are two incarnations available: a traditional installer (.exe program) and a compressed package (in .zip format).

The installer unfolds a very straightforward installation process, characterized by the well-known next-next-finish idiosyncrasy. It automatically installs the JDK if not already present. Finally, it runs the SDK Manager utility once the installation process finishes. The distribution package in the form of a zip archive is fully functional and only needs to be extracted to some directory of your choosing (provided that there is already a working version of Java installed).

The download links for each of these files can be found at the SDK home page in the Android Developers Website, in the section named "SDK Tools Only", under the collapsible "View all downloads and sizes". By July 31 (2014), the latest publicly available version of the Android SDK is r23.0.2, so the respective file names for the aforementioned packages are: installer_r23.0.2-windows.exe and android-sdk_r23.0.2-windows.zip.

For the remaining sections of this article, it is assumed that the Android SDK was installed to x:\android\sdk and the subdirectories under this node will be addressed by their respective relative path, to any depth required. Irrespective of the chosen installation method, the SDK's root directory should look something like this:


Figure 1: Android SDK root directory.

Two executable files will immediately draw your attention. These are the main utility programs used to configure your Android SDK installation. The SDK Manager.exe program is used to add and remove features, platforms, tools and plugins to and from the SDK. The AVD Manager.exe utility is used to create and configure Android Virtual Devices (AVDs). An AVD is a virtual appliance that can be emulated using your own computer's hardware, in which you can run and test an app without the need for an actual physical Android device.

Final adjustments

There are a few final adjustments that are in order before being able to build and run an Android app with the stand-alone SDK when you have only installed the starter package. You need to install the platform tools (blue wrench icon in Figure 2) and the build tools (green wrench icon). These tools collectively conform the foundation of the build system. Amongst the tools, there are source code file generators, compilers, debug utils and so on.

You will also have to install one or more so called platforms (folder icon with the lurking green robot). Platform nodes contain detailed specifications, documentation and samples pertaining to a particular Android Platform release. These define the runtime and API levels against which apps can be built to run. They also provide system images (blue screen device icon), which are used to create virtual devices on which you can run and test Android apps targeting that particular Platform release.


Figure 2: Add packages to the Android SDK (step #3).

Google USB Driver

Additionally, if you are lucky enough to have an actual Android-powered physical device in which you would like to test your own apps, you should also download the Google USB Driver package, under the Extras folder from within the SDK Manager. This driver is used to deploy and debug apps on real devices, basically.

After you install the package, you should proceed to install the driver itself. Installing the package means that its files are downloaded and stored under the .\extras subdirectory in the SDK root directory. The driver is not yet installed in the host system. You must run the driver installer from its location at extras\google\usb_driver.

More information about the driver can be found here:
http://developer.android.com/sdk/win-usb.html

Almost done

Technically, you are all set to write a bunch of lines of code in Java and turn them into a shiny new Android app. But let's be honest: command line compilation, packaging and deployment is just not that fun anymore these days. If you are not using the Eclipse IDE, you might find Android Studio just as useful and maybe a little more appealing to Android development (at least slightly better than having to learn all the obscure ins an outs of command line sorcery).

Android Studio

Android Studio is currently in beta, but it is expected to be constantly improved with bug fixes and exciting new features in the near future. There are, same as with Eclipse ADT, two different packages for Android Studio: a bundled version and a stand-alone version. As it should be expected, the bundled version has the SDK already tucked under the IDE's hood. The stand-alone version bears only the IDE's essential files.

The Android Studio Bundle can be downloaded at:
http://developer.android.com/sdk/installing/studio.html#download-ide-button

To get the stand-alone version of Android Studio, go to:
http://tools.android.com/download/studio

If you chose to install the stand-alone version, you must set the IDE to point to an already installed version of the SDK. In the IDE's welcome screen, select Configure -> Project Defaults -> Project Structure (Figure 3). In the dialog that appears, set the Android SDK location text to the path of the root directory to your SDK installation as in Figure 4 (x:\android\sdk, for example).


Figure 3: Default project structure configuration.

A word of advice: Android Studio comes with an auto-update feature which is enabled by default. When using the bundled distribution of this IDE (the one that includes the SDK), updates have the undesirable side-effect of wiping any change the developer might have made to the SDK installation that lies within the deployed package. That is very unfortunate. To avoid any headaches and save you from the tedious labor of having to re-configure the SDK on every update, you are advised to make a backup copy of the SDK before updating and then restore it aferwards. Alternatively, opt to use the stand-alone distributions of both the SDK and the IDE. As an extreme measure, you can disable updates all along. Updates can be disabled by modifying its corresponding settings in the IDE.


Figure 4: Android SDK location configuration in Android Studio.

Common issues and workarounds

There are too many times in the lives of keen software developers when they would think to have done everything right and that things should simply work. Then, out of nowhere, a nasty bug makes its grim entry into the scene and bites you like it is its purpose of existence. Your head becomes a big question mark that progressively turns red as seconds pass. Then you count to 0x0a, take a deep breath, sip from the coffee mug and open your favorite web search page.

Following are some tips that can hopefully save you from such episodes as the one described earlier.

The Android SDK and its Java version hiccups

Sometimes the tools in the Android SDK can't find nor recognize Java, even though it is already installed and working properly. If you are lucky enough, you will have an error message show up that might shed some light on what the problem is. Otherwise, the program could just close without a warning or even a polite goodbye gesture. This can be the case with the SDK Manager utility, for example. This problem arises most likely because your installed JDK is a 64 bits version, or if it is Java 8.

Solution

There are several ways in which this can be solved. The simplest is to add the environment variable JAVA_HOME to the system. The value of this variable must be set to the path where the JDK is installed. For example: C:\Program Files\Java\jdk1.8.0_11. Reportedly, there have been cases in which the backslashes caused problems too and they had to be replaced by regular forward slashes. You might also get along by making sure that the bin directory of your JDK is included in the PATH environment variable. Overbold ways to solve the problem involve the modification of either: the Windows registry, or the file at tools\lib\find_java.bat inside the SDK.

For more information about this particular problem, please consult:
http://stackoverflow.com/questions/4382178/android-sdk-installation-doesnt-find-jdk

If you need guidance on how to set an environment variable in Windows, check:
http://best-windows.vlaurie.com/environment-variables.html or
http://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them

Summary

Congratulations! You have successfully configured your own environment for Android development on Windows. Remember that the SDK installation is essentially XCOPY deployed. So, if you need to configure a development environment for Android in another Windows PC, you can just install the JDK and copy the Android SDK from its root directory. Additionally, you might need to install the Google USB Driver on the new target system. That would be it. There is no need to download all the contents again from the online repositories through the SDK Manager.

Next steps

Your next steps into this journey would include creating a new project, building an app and deploying it to an Android device for testing. Those are the chapters to a story for some other time, actually. You are encouraged to try all these by yourself; it is intuitive enough. Go play with the IDE, get familiar with it. It doesn't bite (too hard). In articles to come, guidance and insight will be provided to complete those challenges and broaden the possibilities. For now, let's just call it a day.

Wish you good luck, infinite patience and a happy learning + programming experience.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Leandro Taset
Software Developer
Venezuela Venezuela
Universidad de las Ciencias Informáticas (UCI-2008)


Taset was born a few years ago, in a place whose name doesn't really matter. Ever since he first played the dazzlingly astonishing games of tetris and digger, he realized that becoming a programmer his goal to pursue was, and later join the light and open side of the source he would.

Started coding at early years with MSX-BASIC for the Z80 processor, just for the fun sake of it. Then met Borland's Turbo Pascal and C++ later on in his life. One day he got serious about it and went to college to get a degree in anything that was related to computers and the fine art of cranking programs out for them (some snobs call it Software Development —all with the cap letters, neon lights and such).

A gloomy afternoon in the spring of 2004, he heard from a friend about the website at www.codeproject.com and his fate was, for good, sealed to doom.

Follow on   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 2 Aug 2014
Article Copyright 2014 by Leandro Taset
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid