So you want to make an Android app for fun or profit using Android Studio? This guide is an updated “How To” covering the basics of setting up Android Studio and building a simple application.
If you are the book-reading sort, you may also be interested in reading this:Getting Started with Android Studio 2nd Edition (Mobile Development)
This guide will cover the following:
- A lightweight overview of a few core Android concepts
- Setting up and installing necessary Android tools
- Creating a simple PageView application
- Some very basic interface design
- Running the application in an emulator and seeing it work
Step 1: Get Installed
Please do the following before we get started:
- Download Android Studio from this link: http://developer.android.com/sdk/installing/studio.html
- Follow the installer instructions posted by Google as per your operating system
Installing Android SDKs In Android Studio
Once you have installed Android Studio, you will now need to download a collection of tools and SDKs required to produce a modern Android application.
Note: If you are on OSX Mavericks you might get a message stating “Android Studio Can’t be opened because it is from an unidentified developer.”
To get around this issue, navigate to the directory in Finder and “Control + Click” the Android Studio application and then click “Open” from the menu. You will then receive a new dialog which now has an “open” option. Problem solved.
Just skip this dialog by clicking “ok” here unless you have a previous installation you’d like to import settings from.
We should now be ready to start doing fun Android things…such as installing a whole bunch of SDKs and utilities!
Install All The Things
Note: You can skip this if you already have Android 4.4 related items installed. Otherwise, it may be helpful just to get a sense of what the possibilities are for working with different Android flavors.
Android Studio comes default with some basic Android tools to get up and running but it never hurts to get the latest of whatever you are developing on.
Begin by navigating to Tools->Android->SDK Manager.
This is the Android SDK Manager. You can install any older flavor of Android here as well as older tools for working with those prior Androids. For now, just verify that the 4.4 SDK is installed (just click the top level folder for 4.4 and it will select everything in that folder) and then make sure “Android SDK Tools” and “Android Platform Tools” have been selected as well.
Now click “Install 11 packages down at the bottom.”
Click the top-level item in the left hand pane and then click “Accept License” and then “Install.” Things should begin installing now.
Time For Your First Project
You will now see the following.Because we are creating a new application, we shall select “New Project” at the top.
As you can see there are a large number of possible configurations you can target here as well as custom Android themes you can select. Styles and themes are a way to globally configure the look and feel of your Android app, read more about this topic here.
You can also select a minimum SDK target and target as well as a few other options which are not of importance at this time. If you ever want to build an app and release it to a wide range of users across many devices these settings become increasingly important.
The package name is what is known as a “namespace.” Essentially this is a unique identifier to prevent other applications from getting your files confused with theirs. The form of name spaces takes a “com.x.y” format and is partially based on the domain name formatting of the world wide web.
Go ahead and do the following:
- Change the application name field to “Hello World”
- Change the package name to “com.hello.world”
- Click “Next”
This screen allows you to set a custom Android app icon. If no icon is selected, the default green droid icon will be used. If you have a custom icon, provide Android Studio with the path and it will show how the icon renders given different screen sizes and resolutions on the right hand side. You may also apply some limited default modifications to your icon appearance.
Click “Next” again on this screen.
Three options here. The “Blank Activity” contains nothing and it will be up to you to provide the initial view yourself aside from a navigation bar. For the “Fullscreen Activity,” the navigation bar is hidden. The “Master / Detail Flow” option is generally suited for tablet applications and contains an arrangement of sub-views common for viewing a list of elements and a large detail element.
For now we will just stick with the blank activity.
Click “Next” again.
I will provide some brief detail on the options here. An “Activity” is the fundamental view structure for Android. You can think of an Activity as a “Screen.” A layout is an Android concept captured in an “.xml” file which states what elements will appear inside the main Android activity such as buttons, sliders and other fun controls. A “Fragment” is a UI subcomponent which is meant to provide the benefit of reusability. A fragment is sort of like a mini-activity which can occur inside an Activity and has it’s own life cycle. They even have their own activities called “FragmentActivities” which likewise provide the benefit of transferability. You can even use multiple fragments together on the same screen.
Select the “Navigation type” drop down and choose “Swipe Views.” These options encapsulate some common Android app structures and are provided as basic navigation templates.
Note: Gradle is what is known as a “build automation” tool. Basically what it does is magically take care of setting up your Android app and configuring it properly given all the settings you selected during the set up process.