I've recently decided to begin my adventures in Android development after years and years of doodling down ideas that I thought would make awesome apps. Developing for the same platform day in and day out gets to be very tedious at times So before I give on software development and become an Alaskan fisherman I'll take a dive into making phone apps. I'm brand new to Android development. I've never touched it or read up on it, so this is a first hands on look at the process from installing the SDK to configuring the emulator to getting those first strings of "Hello World" to appear on the screen. I'll be writing this as I myself progress, so let's see what develops.
Download the SDK
Normally you develop Android apps using Eclipse and the Android SDK ADT. However, Android Studio is currently out now in BETA, as of this post, so I figured I'd give it a shot, to stay ahead of the curve if you will. Android Studio is based off of IntelliJ IDEA and will at some point be the official Android Development suite once it's ready. The only downside is that most of the documentation on Android development is written with Eclipse in mind currently. However, after spending some time with Android Studio, it doesn't look to be too different than Eclipse, at least not for the beginning stages anyhow. If you would like to use Eclipse however, you can just install the Eclipse ADT package here. To stay consistent with the online documentation all the snapshots I have here are made using Eclipse.
Installing the SDK is pretty straightforward. You double click the .exe, and it runs and you click 'yes' several times. The only snag I hit was when attempting to install it on my spare Windows 8 machine. Right at the 90% completed point, I kept getting a "Filename is too long" exception and that's where the installation ended. There is a quick solution to that problem however. Just extract the Eclipse files to a short named directory. By default it attempts to extract to your "download" folder, which is higher up in the directory tree than Eclipse would like. So make a new directory in your C: drive, and you should be good to go.
Once you've installed the SDK you get a default template project that just spits "hello world" back out. There's tons of files and buttons to click, but for now let's be comfortable knowing that we have a full project ready to run.
Create An AVD (Android Virtual Device)
In order to run your application you will either need your Android phone set with debugging enabled, or more readily available an emulator running on your machine. In order to do that, you will need to first define what device you would like to emulate and configure it accordingly. This is your AVD. When I first tried this, it took a while. And I mean a while. After some research I realized that I didn't have all of the correct sdk packages installed, and so I had to sit there and wait..and wait. We can ignore a few of the settings in the "create new AVD" form for now. We just need a name, the device such as Nexus 4 or Nexus 5, the target Android version which is the highest version of Android with which you have tested your application. You can set the amount of RAM with which you want to run your emulator on. On Windows it might be a good idea to start low then work your way, as this can considerably slow down your machine.
The snapshot feature is used to quickly launch the emulator on subsequent runs, which is super convenient considering how slow the emulator can run. At some point you will probably end up using all of the features shown, but for now we're good with the basics. If you don't want to use the predefined devices given in the dropdown, you can in fact create your own. I won't do that just yet, but I might cover it at some point down the road.
Download the Proper API's From Android SDK Manager
Open up your SDK Manager and be sure that you have all the required modules, API's and tools installed otherwise you'll be in for a treat. The first time I ran it I was missing the CPU images for the Android version that I was targeting. It looks like a quick and simple download, but some of these packages run hundreds of megabytes, so you'll be waiting for a bit if you want to have all versions and all images and all tools installed. I also noticed many of the downloads stopping halfway short and having to be redownloaded. Not sure if it's a generic issue or maybe just on my machine.
Running Your Application
We should now have a default project, and however many AVD's we decided to create for testing. Normally, you hit f5 and your application is ready to go. Unfortunately, it wasn't as smooth a process for me this time around. Aside from surprisingly long build times, I received a black screen as my reward. Not only that, but my laptop was not the same for about an hour. After some research I ended up creating several different device configurations in the hopes that at least one would run.
Here's a tip: Don't just edit the AVD's when you're looking to work with a new one. Just create a brand new one from scratch with whatever settings you need. I noticed many a time that the settings were correct, but it wasn't functioning correctly regardless, and after creating a fresh AVD it ran just fine. There was some success as I received a page with the android splash screen. But then nothing much else after that for about 30 minutes. I tried reducing the amount of RAM being used and targeted lower Android versions and still about the same speeds. As there isn't much point in continuing without a proper emulator, I had to find a proper solution which I more or less did.
After waiting 20 minutes to load the emulator I started to research ways to improve the speed. An hour or two later I learned about HAXM. The Intel "Hardware Accelerated Execution Manager", or HAXM for short, is a hypervisor that adds hardware acceleration to Intel images in the SDK. Before installing it, you need to make sure that your chipset will support it. There is a list right here that can help you with figuring that out.
After installing HAXM from the SDK Manager, you will need to run the installer. Another Tip: After spending some time looking directory by directory for it, I just did a quick windows search for "Hardware Accelerated..." and ran it from there. With HAXM installed, you can create new AVD's that make use of the host GPU and the Intel x86 images that are also available through the SDK Manager. The one downside is that you do lose the snapshot ability which offers quick start times. But what you gain is worth it. After setting the max limit of RAM usage for the image, you get super fast emulator performance.
Create your AVD's with the host GPU checkbox marked and targeting the Intel Atom x86 CPU for the improved performance.
That's it for Day 1. I was expecting a few hiccups here and there, but 1 full day for configuration is not awesome, but it comes with the territory, and I learned a fair bit about the SDK and Android emulation. And I hope my trial and errors help out anyone that's starting out by saving them a few hours. The development environment is half the battle usually. Now that I have a super fast emulator and several AVD's to work with, I can get started on learning how Android handles pages and controls.
Just to recap the whole thing. Install the Eclipse ADT package or Android Studio, both of which are pretty similar for first timers. After that load up the SDK Manager and install any necessary files and modules that you might need. Also download and run the HAXM installer while you're at it, as this will help us later when running our emulators. Create a new AVD to test our projects on and configure it as mentioned above and then run it. And we are good to go.
Thumbs up if you enjoyed this post!
Suggest the next blog post
Walter G. is a software engineer with over 10 years of professional experience. When he isn't blogging or being a CTO he enjoys coding randomly complex things that he hopes many people will get a chance to use one day.