Wednesday, January 7, 2015

Getting started with Android Studio

It's official! At long last Android Studio 1.0 is a thing. For anyone who is new to Android development or has yet to try Android Studio here is a short walk-through to help you navigate installing Android Studio and building your first app.

Step 0. Install Java 7

If you already have Java 7 installed you may skip to step 1.

Java 7 is required for Android Studio and can be downloaded directly from the official site. Make sure you download the correct package for your computer's operating system and architecture.


Follow the installation instructions for your operating system. When finished open a command prompt and enter "java -version". You should see something like the following:

$ java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Be sure to install the full Java Development Kit (JDK) and not just the Java Runtime Environment (JRE). As of writing this article the current version is 7u71.

Step 1. Install Android Studio

Navigate to developer.android.com/sdk and click on the big green button to download Android Studio.


After the download completes follow the instructions on the screen to install and setup Android Studio. The first time you launch Android Studio you should see the following.


When you are finished with this step you are ready to install additional SDK packages.

Step 2. Add SDK Packages

Out of the box the Android SDK does not come with any platforms included. It does not even include all the tools you will need to build your first app.

Follow the instructions to download and install additional SDK packages including Android SDK Tools, Android SDK Platform-tools, Android SDK Build-tools, Android 5.0.1 (API 21), Android Support Repository, and Android Support Library. Hint: This may take a while.



Once all SDK components have been installed you are ready to begin building your first app.

Step 3. Build Your First App

Follow the instructions in the online tutorial for Creating an Android Project. Once you finish creating your Hello world! project you will need a device or emulator to run your app.

I highly recommend using a real Android phone or tablet if you have one available. If you don't have an Android device available then you can use the emulator.

If this is the first time you've use this device for development you'll need to enable developer options and USB debugging. Here is a short video that might be helpful.


Once your device or emulator is ready you can run the app by clicking on the Run button in the top toolbar.


Choose your device or emulator from the popup window and click OK.


Wait a few seconds for the project to build and deploy and then you should see your app running on your emulator or device. That's it!


Next Steps

You can continue the official tutorial with Building a Simple User Interface and then Starting Another Activity. Or call it a day and crack a cold one. Your choice.

Tips & Tricks

I also recommend checking out Android Studio Tips and Tricks. By far the two most important are Ctrl + Shft + A (command look-up) and Alt + Enter (quick fix).

Command look-up lets you search for any command just by starting to type it. For example if I want to rename MainActivity to something else and I forgot the keyboard shortcut to rename is Shft + F6 I can simply hit Ctrl + Shft + A and start typing "rename".


Quick fix is one of the best things about Android Studio (and IntelliJ IDEA). When you have an issue in your project it is usually shown in red. Hover over the error with your mouse and hit Alt + Enter and Android Studio will fix the problem for you. If it can't automatically fix the issue it will suggest a list of possible solutions.

In this example we accidentally deleted the last letter of savedInstanceState. Android Studio gives us a list of possible solutions including the correct solution which is renaming "savedInstanceStat" to "savedInstanceState".

 

Learning a new development environment can be tedious. Hopefully this guide will help you get started. And if you run into any issues just remember...

"Keep Calm and Alt + Enter"

 

No comments:

Post a Comment