1 of 37

Android Studio Setup

Prepare your environment for Android

2 of 37

Overview

  1. Install Android Studio IDE

  • Basic setup of Android Studio - Editor settings, Android SDKs and tools

  • Download sample app using Git and import it into Android Studio

  • Setting up the official Android emulator to run different Android OSes

  • Run Sample App

3 of 37

Android Studio -- Why?

Android Studio is the latest development environment Google recommends for Android. It is based on IntelliJ IDEA which is faster and lighter than Eclipse.

When developing apps for Android, we will need Java SDK, Android SDK as well as the Android Studio IDE.

4 of 37

1. Android Studio

Installing Android Studio

5 of 37

Installing Android Studio

Download Android Studio which also includes an initial setup for Android SDK tools:

1. Download Android Studio

https://developer.android.com/studio/index.html

2. For OS-specific instructions, follow: https://developer.android.com/studio/install.html?pkg=studio

3. Launch Android Studio Application

6 of 37

Setting up Android Studio, 1

A newly installed Android Studio should now prompt you to use the wizard to setup the Android Studio.

  1. Click “Next” to continue through the wizard.
  2. Select the “Standard” installation.
  3. Click “Finish

7 of 37

Setting up Android Studio, 2

If installation succeeds, you should see the “Silent Installation Pass!” in “Show Details”�

Click “Finish

8 of 37

Troubleshoot: Intel HAXM

In order for Intel HAXM to work, your computer must support virtualization. In some cases, computers support virtualization, but it is not enabled in the BIOS. In this case, when you try to install Intel HAXM, it will say something like:

"Your hardware supports virtualization, but it is not enabled. Restart your computer, navigate to your BIOS system settings and enable virtualization."

OSX machines usually have virtualization support already enabled.

For for information/help you can refer to https://developer.android.com/studio/run/emulator-acceleration.html

9 of 37

2. Studio Setup

Configuring Android Studio

10 of 37

Configure

Select “Configure

and then “Preferences” in the bottom menu.

11 of 37

Configure Line Numbers

1. Find Editor → General → Appearance

2. Enable “Show line numbers”

12 of 37

Configure Imports

1. Find Editor → General → Auto Import

2. Set “Imports on Paste” to “All

3. Click “Optimize imports on the fly”

4. Check “Add unambiguous imports on the fly”

5. Exclude android.R from auto-imports

13 of 37

Configure SDKs

Select “Configure

and then “SDK Manager” in Menu

14 of 37

Android add-ons, 1

  1. Check the following boxes:
  2. Android 7.1 (API 25)
  3. Android 6.0 (API 23)
  4. Android 4.4 (API 19)

  • Check ‘Show Package Details’ in the bottom right corner
  • Under Android 7.1.1 and Android 4.4 Select ‘Google APIs x86 Atom 64 System Image’

Click 'Apply' button once all versions are selected.

15 of 37

Android add-ons, 2

Check the following boxes:

  • Android SDK Tools
  • Android Emulator
  • Android SDK Platform-Tools
  • Android SDK Tools
  • Google Play services
  • Google USB Driver (Windows)
  • Intel x86 HAXM
  • Support Repository

Click 'Apply' button once all versions are selected.

16 of 37

3. Hello World with Git

Version control with Android Studio

17 of 37

Git -- Why?

When developing software, we should always use version control to manage our code.

Version control with Git is a way to backup our code, create a version history as we make changes and collaborate on code with other developers.

For our purposes, we will be using GitHub to store our code. GitHub is a free service for managing our code and saving a backup in the cloud.

We will also download and run our first Android application using Git.

18 of 37

Setup Git Client and Github

It is recommended to use the Git command-line tool. If you don’t have it, you can download it from https://git-scm.com/downloads

�The course will be using Github to store projects. Setup your account on https://github.com

�Learn basics of Git using:-

19 of 37

Clone HelloWorldDemo

In your terminal perform the following actions:-�

  1. cd to the directory you want to download the sample project�
  2. Run git clone https://github.com/codepath/android_hello_world.git

20 of 37

Import HelloWorldDemo

  1. Switch to Android Studio and close any open projects.
  2. In Android Studio dialog, select Import Project...
  3. In that dialog, find the android_hello_world project just downloaded.
  4. Select build.gradle under the android_hello_demo path
  5. Click "Ok" to Load the Project

21 of 37

4. Android Emulator

Running Android Apps in Android Studio

22 of 37

Emulator -- Why?

Android Development requires us to try the apps we are building while they are being built.

While this can be done by plugging in an Android device, usually it is easier to use an Emulator.

An Emulator runs the app in a virtual Android on your computer through Android Studio.

There are two emulator options: Genymotion or Intel HAXM. We recommend using Genymotion if possible but requires at least 4GB of RAM.

23 of 37

Create Virtual Device

Select Create Virtual Device to add new virtual device

24 of 37

Setup Virtual Device - 1

Select Nexus S as the device to run the Android OS on

25 of 37

Setup Virtual Device - 2

Select x86 Images tab. Then select Nougat which you downloaded earlier as part of the SDK setup. If you haven’t then click Download next to the platform

26 of 37

Setup Virtual Device - 4

Select x86 Images tab. Then select Nougat which you downloaded earlier as part of the SDK setup. If you haven’t then click Download next to the platform

27 of 37

Setup Virtual Device - 5

Verify the configuration. It is ok to leave the default configuration as is. Click on Show Advanced Settings to know more about the configuration.

Then click Finish

28 of 37

Launch Android Emulator

For the virtual device that you create, click on the "Green Play Icon" to launch in the emulator. Starting the emulator for the first time make take a few minutes. Don't close the window once it has booted.

29 of 37

Confirm Installation

  1. Launch official emulator
  2. In Android Studio, click on Run → Run ‘android_hello_world’
  3. Wait for Gradle to build
  4. App should eventually load in emulator window
  5. You should now see the application running in the emulator!

Note: If this doesn’t run, try creating a new project instead with File → New → New Project and clicking “Next” and “Finish”

30 of 37

Genymotion

Genymotion requires a few extra steps but is the current recommended Android emulator to use. See link below and next slides.

http://bit.ly/1IscAhq

On PC’s: You must enable Virtualization Technology in the BIOS.

31 of 37

Genymotion, Installation

First steps in the Genymotion guide in the previous slide are:

  1. Sign up for a genymotion account
  2. Download and install Virtualbox to your system
  3. Download and install Genymotion.
  4. Install the Genymotion plugin within Android Studio

Follow the guide above for the details.

32 of 37

Genymotion, Configure

Next steps in the guide in the previous slide are:

  1. Launch “Genymotion” app
  2. Configure ADB settings
  3. Add a “Google Nexus 5 - API 19” device
  4. Configure the Genymotion plugin in Android Studio

Follow the guide above for details.

33 of 37

Genymotion, Verify

Let’s verify our Genymotion setup by launching an emulator:

  • Select the Nexus 5 device, API 19
  • Press “Start” to boot emulator
  • Wait for the emulator to load
  • Click “OK” on the emulator to dismiss any dialogs or popups
  • If the emulator seems to be working, then we are set!

We’ll be using this emulator to test our app as we develop.

34 of 37

Testing on physical device

We can also test an app on a physical device. This requires connecting the physical device to the computer using USB cable and performing additional setup. See link below for details:-

http://bit.ly/2rZTls1

It is a must to test an app on a physical device before releasing it as the emulator is only a simulation of a device and can not replicate all the internal workings of a physical device

35 of 37

Change default layout template

To make development easier, it is important to change the default template layout which is ConstraintLayout to RelativeLayout.

ConstraintLayout is a new UI layout that is considered to be more powerful and flexible than RelativeLayout but is not as mature so can have unexpected challenges.

By using RelativeLayout for now, it will make development easier. See the link below for details:-

http://bit.ly/2qU5Ibx

The file is located in /Applications/Android Studio.app/Contents/plugins/android/lib/templates/activities/common/root/res/layout/

36 of 37

5. Wrapping Up

Ensuring Setup is Complete

37 of 37

In Review

We have now finished setting up our Android environment including:

  • Android Studio IDE
  • Android SDK
  • Version Control with Git
  • Setup Our First Android Application
  • Android Emulator