Optional Processes (Windows/Mac)

Test Environment

Before creating a real app, you may want to test the development environment on a sample app to see how everything works. As a common practice, a "Hello World" app will be created.

  1. Open Android Studio and from the Welcome screen, click Start a new Android Studio project and give the app a name (e.g., "Hello World").

    TIP: To start Android Studio on the Mac, click on the spotlight icon at the top of the screen (or CMD+SPACEBAR) and type Android Studio.
    1. In the New Project dialog box that appears:
    2. Type an Application name (e.g., Hello World) in the text field. It will be used in several places:
      • on the app's home page
      • as part of the app's icon name
      • as part of the package name
    3. Type the Company Domain (e.g., example.com) in the text field.
      NOTE: Company Domain does not need to be a actual domain.
    4. CHECKPOINT: The Company Domain will be used to convert to the MAIN package name that is dimmed out in the next field. It is updated to reflect a reverse domain notation and the application (ID) name. However, you can edit this name by clicking on the Edit link to the right of the screen. It is a unique name that is used to identify the app in the app store.
      TIP: By using the same package name for all of your sample apps, you willl be able to replace any existing apps on your testing devices each time you install a new one and you will not have a host of apps that you will have to find and delete.

  2. Accept the default project location.

    NOTE: By default, Android Studio creates a project subfolder under the home folder called AndroidStudioProjects but you can place the project anywhere you want. You could, for example, you could click on the browser button and create an new folder on the Desktop and save your project them for convenience). By default, configurations are global to the entire Android Studio installation. Notice also the project is AUTOMATICALLY named the SAME as the Application name but WITHOUT spaces (e.g., ...AndroidStudioProjects\HelloWorld).

  3. Click the Next button.


    NOTE: The package name is important because no two apps in the Google Play store can have the same name.

  4. In the Target Android Devices dialog box that appears, select a form factor(s) you want to use. By default, Phones and Tablets are selected. Keep the default.
  5. Choose a Minimum SDK that will be required for your app to run. Keep default.

    NOTE: If you're not sure, click the Help me choose link to see a listing of all the currently-active versions of Android. Click a link to learn about each. You can also click on the link at the bottom of the screen or go to https://developer.android.com/about/dashboards/.

  6. Click the Next button.


  7. In the Add an activity to Mobile dialog box that appears, select an Activity (e.g., Blank Activity). Keep default.

    NOTE: An activity is the app's primary screen. The blank activity is a very simple template that will display a text on the screen. As an example, the Master Detail Flow template creates a master and detail activities and uses the Fragments API so that the app will look different on various devices. An activity is similar to a View control in iOS app development.

  8. Click the Next button.


  9. In the Customize the Activity dialog box that appears, review options that will be created.

    NOTE: The Name and Title are Java classes and will not be seen by any user. The Layout Name and the Menu Resource Name are resource identifiers. They can be left at their default values.

  10. Click the Finish button to create the project.

    NOTE: If only a single screen is being used, leave the values at their defaults.


    NOTE: For every activity (akin to a page) that is created as a *.java file, there is a corresponding xml file. The *.java file has a method called setContentView (e.g., setContentView(R.layout.activity_main;) which is used as the name implies to set the content view for that page. The folowing describe the inputs above:
    1. Activity Name is the Java file that will be created for the project's code
    2. Layout Name is an XML file that will be created for the project's layout
    3. Title is as the name implies the app's title that will be shown at the top of the app???
    4. Menu Resource Name is an XML file that will be created for the project's menu

  11. If the Windows Security Alert dialog box appears,  unselect Public and select Private and then click the Allow access button.


    NOTE: The first time an Android Studio project is created, it takes a while to complete because it has to download components locally. However, when you create other projects, it should go quickly. If you see the Tip of the Day dialog box, you can click the Next Tip button to learn more about Android Studio or simply close the dialog box.

  12. Pay attention to the message (e.g., indexing) at the bottom of the screen. When the message goes away, you are ready to develop an app.
  13. If you get a Rendering problem, from the drop down menu, switch to a different AVD.


  14. CHECK POINT: By default, there will two tabs that are open for each project you create. The Java file is for the main activity class which is a collection of Java classes and the other is its associated XML file that defines the layout. Also, by default, a virtual device will be displayed (e.g., Nexus 4). If you want to change that view, select another device from the list.

Review Project Tab

There are several views in the Project window. If you don't see it:

  1. Click the Project tab in the left panel.
  2. Click the Project link in the lower left corner of the screen.

1. Android View

The Android is the default view which organizes assets by type to shows the most important folders and files but does not reflect the actual structure on the computer. In this view, files are hidden that are are used to manager Android Studio so you can focus on files that are modified the most (manifest, java, resources, and Gradle Scripts).

app folder contains:

Gradle Scripts contains:

It is best practice to used the Android view for most development work and use the Project view to view other project files that are not needed on a regular basis.
NOTE: Gradle is the build engine or tool that is used to create an app.

2. Project View

To see the actual directory structure, switch to the Project view (ALT+1 (PC) or CMD+1(Mac)). Android Studio project directory and file names that are always the same. If you hover over the top-level node, you will see the actual location of the project.
TIP: To see the actual folder in your file manager, right-click on the top-level item and select Reveal in Finder on the Mac or Reveal in Explorer on Windows.
NOTE: The other views arrange the structure for a particular perspective or purpose.

If you click on the top-level node, you will see all of the project assets:

The app folder is a module directory. Each project can have multiple modules with each module represented by a directory. To see what module(s) are included in a project, select File > Project Structure... and in the Project Structure dialog box that appears, in the left panel, you will see what Module(s) are included with the project:

3. Project Files

Project Files directories:
If you are a new Android developer, this is the view that you should be using because it filters out most of the files that are not requires.

4. Packages View

This view presents Java classes and resource files all together in single tree format.

Other views include:

5. Scratches

This view allows you to copy "scratches" of code that you can use later. To do this, copy some code and then from the menu select Tools > New Scratch File.... so that it appears in a new scratch file. Close the scratch file and then switch to the Android scope and then return the the Scratches panel. You should now see the scratch file listed.

6. Problems

Show files that need fixing. To test:

  1. Create an error (e.g., remove a required semicolon) from a *.java file and then close it.
  2. Return to the Problems panel and then navigate to the file that has a "problem" and double-click it to open it
  3. To go to the "problem" area press the F2 key and the cursor will go to the location of the problem. You may need to expand the code to see it.
  4. Fix the problmem (e.g., add the required semicolon) and you should see the problem item removed from the Problems panel.

7. Production

Show Java, resource and generated files that are required for production when the app is package.

8. Tests

Show files that are required for jUnit tests. To test a test:

  1. Navigate to the test file (ExampleUnitTest) and click on it to open it. It has a simple test to see if a class will work.
  2. Right-click on the class and select Run "ExampleUnitTest" from the menu.

    NOTE: This is only a Java test and does not anything to do with an app.

9. Android Instrumentation Tests

Thisr test that works with virtual and physical devices. To test:

  1. Navigate to the test file (ApplicationTest) and click on it to open it.
  2. Right-click on the class and select Run "ApplicationTest" from the menu.

    NOTE: For more information, go to the link in the test file (e.g., http://d.android.com/tools/testings/testing_android.html).

Review Structure Tab

The Structure tab (CMD+7 on Mac or ALT+7 on Windows) can be used to show a "structure" view of the Java classes along with their methods. They are shown by default in the order they are declared. However, you can sort them in any order you want (e.g., alphabetically, by visibility--access modifier). You can also determine what members of the class is going to be displayed. By defualt, you will see fields and non-public members.

Captures Tab

The Captures tab can be used to "capture" the result of other panels (e.g., Memory) for review later.

Build Variants Tab

The Build Variants tab can be used to "build" different "variants" of your app. By default, you will used the debug variant. However, when you are ready to publish your app for deployment, you will need to use the release variant to build your app.

Favorites Tab

The Favorites tab can be used to save your "favorites" classes and other resources that you like to use often. By default, you will see three items available (Project, Bookmarks and Breakpoints). You can add items to the Favorites from the one of the Project windows. Find what you want to save to Favoriates and then right-click on it and select Add to Favorites and then add to the Project or to an New Favorite List. To open a Favorite, double-click on it.

Message Tab

The Message tab (CMD+0 on Mac or ALT+0 on Windows) can be used to provide a listing "messages" from the Gradle build tool. It is different from the Problems tab that is used for Java errors. The Message tab is used to display messages when the app is being built. Double-click on the TODO comment to have the cursor move to the place where the comment is. You can also filter your TODO comment based on the currrent file or a scope (e.g., Project, Android, Package)

Android Monitor Tab

The Android Monitor tab is used to access to logcat output. By default there is only the Memory monitor. However, if you double-click on the Anroid Monitor tab, it will allow you to view the CPU, Network and GPU monitors as well. However, these monitors will only be active when you are running a virtual or physical device. Whenever you run your app, the Android Monitor window will open automatically.

TODO Tab

The TODO tab is used to show a list of "To Dos" comments that you want to write to yourself or others. To write a TODO comment start with a double slash, type the word TODO follow by a space and then the comment (e.g., // TODO Add more code to this class later). Then, the TODO comment will be shown in the TODO panel.

Terminal Tab

The terminal tab is used to open a command prompt. On Windows, it opens a simple command prompt and on the Mac, it opens the terminal app. You can run any command that you can on your Operating System (e.g., ls or dir for directory listing on teh Mac and Windows, respectively).

Gradle Tab

The Gradle tab is used to ...

Android Model Tab

The Android Model tat is used to ...

Modify Gradle Scripts

The Android project window has a virtual folder called GradleScripts that contain two Gradle scripts and other configuration files in one place.


There are two build scripts with the SAME name, one is for the project and the other is for the module.

Modify Manifest File

The AndroidManifest.xml is an XML file at the top level of the project that describes to the Android Virtual Machine (ARM):

There are several ways to access this file:

The structure of the manifest file is as follow:

NOTE: It is important to note that an app's configurations are splitted between the Gradle script and the app manifest file.

Modify Resources

Every Android project has a res folder with a host of resource folders in it.

  1. From the Project view, click on app, src, main and then the res folder (physical location).
  2. From the Android view, click on app and then the res folder. Under this folder are the sub-folders that defines:
    • drawable - graphical resources
    • layout - activities or screen appearance (e.g., activity_main.xml) in an xml file
    • menu - menus and action bar items (e.g., menu_main.xml) in an xml file
    • mipmap - launcher icons (e.g., *.png)
    • values - strings, dimensions and styles in xml files (e.g., strings.xml)

However, there are other resources that can be created (e.g., color, xml, transistion) that can be defined in its own file manually or automatically with Android Studio. The SDK document describe these resources detail. To define a brand color that can be used in an app:

  1. Choose File > New... > Android resource file from the list.
  2. In the New Resource File dialog box that appears, assigned it a resource ID name (e.g., my_brand_color.xml).
    NOTE: The resource ID naming convention uses all lower case, no space or no special characters.
  3. Choose Color from the Resource type drop-down
    NOTE: Notice that the Directory name was automatically set to a folder named color.


  4. Click the OK button.
    NOTE: This will automatically create an XML file with and an xml namespace (See below).
  5. Inside the selector element, add an item element with the following highlighted code:
    TIP: Type <it and then select item from the list and press the Enter key. You will be provided a list of colors and their preview to choose from or you can type a literal hex color value (e.g., #0F0) and then close the tag with "/>"

    <selector xmlns:android="http://schema.android.com/apk/res/android">
    <item android:color="#0F0"/>
    </selector>


  6. Save changes by pressing CTRL+S (PC) or CMD+S (Mac).
  7. From the Android view, under the app, res and then layout folder, double-click on the activity_layout.xml file to see it in Design view.
  8. CHECK POINT: You should see the text (e.g., Hello, World) is black.
  9. In the Properties panel, scroll down to the textColor field and click to select it and then click the browser icon with the three elliplse (...).
  10. Scroll down to the newly created colorID (e.g, my_brand_color), select it and then click the OK button.
  11. CHECK POINT: Return to the file and click on the Text tab at the bottom of the screen to see the file in Text view. You should see the attribute added to the TextView (e.g., android:textColor="@color/my_brand_color").
  12. (Optional) Change the text size manually by adding the following attribute below that last one:
    TIP: Type textSize and press the Enter key to add most of the code.

    android:textColor="@color/my_brand_color"
    android:textSize="32sp"

  13. CHECK POINT: Save changes by pressing CTRL+S (PC) or CMD+S (Mac) and previewing the app again in Design and Text view. You should see the font size is bigger.
    NOTE: Like a tag or emeent selector in CSS, if you wanted to change the color for all instances that have this resource assigned to it, simply change the value in the resource file and it will automatically cascade to the other instances in the app.

Modify Support Libraries

Android Studio's dependency system is based on the Maven repository which is a host of libraries where developers can add or download libraries. If you open the build.gradle file, you will see a list of support libraries in the dependencies directives. These libraries were automatically included when you selected the Support Repository checkbox when Android Studio was installed.

You can find the Support Repository by clicking on the SDK Tools tab in the SDK Manager, and then you'll see the Support Repository listed here. During compilation, the build process looks at these directives and unique identifiers for the libraries and the versions you want to use. First, it looks at the local repository copy of the SDK installation to get them. However, if it doesn't, it can be manually added from a remote repository.

If you want to work with JSON (JavaScript Object Notation) formatted data and wanted to use Google's GSON library to include as a dependency, you could follow these steps:

  1. Choose File... > Project Structure and in the dialog box that appears, click on the app Module and then click on the Dependencies tab.
  2. CHECK POINT: Notice that the number of lines match the number of lines in the dependencies block in the gradle.build file.
  3. Click the plus (+) button and select Library dependency from the drop-down list to see a listing of all the known dependencies.
  4. In the Choose Library Dependency dialog box that appears, type GSON in the Search field or scroll down and find it and then click the OK button.
  5. Click the OK button again to close the Project Structure dialog box.
  6. CHECK POINT: You should see it added to the existing list of libraries and as a new compiled directive in the build.gradle file.


  7. To test it, go to the MainActivity class and type the following highlighted code in the onCreate method to create an instance of that class:

    Gson gson = new Gson();

    NOTE: Because the library was added as a dependency in the build.gradle file earlier, notice that Android Studio recognize the class and its package to perform auto-complete.

  8. CHECK POINT: Click on the plus (+) sign next to the import statement at the top of the file to expand it. You should see that it added the import statement for that class.

The bottom line is that you don't have to add a Java library (*.jar) to the projects folder and then adding it to the class path using this method. In the build.gradle file, notices there is a section on repositories that has a reference to a method called jcenter. If you hold down the CTRL or CMD key and then hover the cursor over this method, you see that it is returning an instance of the class named MavenArtifactRepository that is referencing the Bintray website. If you learn how dependencies work, you can add your own repositories to this list and expand the capabilities of the gradle build system.

There are several online open source libraries that are available for Android development. Type in a search field (e.g., gson) to search for a particular library.

Add JAR file to Dependency

Whenever possible, you should use dependencies that refer to remote files. However, that is not always the case (e.g., your own library or a third party library). So you have to add them manually to your project.

  1. Copy a *.jar file from somewhere
  2. Switch to the Project scope and navigate to the app/libs directory and paste the *.jar file into it and in the Copy dialog box that appears, click the OK button.
    ALTERNATIVE: You can also drag-and-drop the *.jar file from the File Explorer on Windows or Finder on Mac.
  3. CHECK POINT: The *.jar file classes might not be available to the app even though the build.gradle file has a directive that specific all jar file in the library be included (e.g., compile fileTree(dir: 'libs' , includes: ['*.jar']).However, if you attempt to create an instance of the class, you may not see that version from the library. To resolve this, right-click on the *.jar file and select Add As Library... and then in the Create Library dialog box that appears, click the OK button which will add it to the dependencies in the build.gradle which will make the library classes immediately available in your app. Now, if you create an instance of the class library, it will show up in the list of classes available.

Add JAR file to Module

Beside adding a JAR file from remote library dependencies or local JAR file dependencies, another way is to "wrap" a JAR file or files with its own module. Which option you choose depends on the project complexity or your own perferences.

  1. Create a new module by selecting File > New > New Modules... and in the New Module dialog box that appears, select the .JAR/.AAR package and then click the Next button.
    NOTE: There is a host of module that you can choose from (e.g., Phone, Tablet, Wear, TV, Glass)
  2. In the next screen that appears, browser to the JAR file that you want to import by clicking on the Browse button and then clicking the OK button and then click the Finish button.
  3. Choose File > Project Structure... and choose the app module and then click on the plus icon (+) at the bottom of the screen and select Module dependency from the drop-down list to tie the module to the app and then click the OK button twice.
  4. CHECK POINT: You can add any Java code that is part of that module and it will be available to your app module.

Developer Docs/Training

Google provides useful documentation and training on-line at developer.android.com/develop, installed off-line documentation with the Android Studio installation or in-place documentation within code. These documentations allow a developer to learn the Android framework by Java Classes and APIs that can be searched or viewed by API version number or name. To access the in-place documention of a selected Class, press CTRL+Q (PC) or F1 (Mac) or hold down the CTRL key and move cursor over a Class name.

On the developer website listed above you can find information on:

News - http://android-developers.blogspot.com/

Questions about Android and programming in general - http://stackoverflow.com/

Import and Export Settings

Once you have established your Android Settings (PC) or Preferences (Mac) to see its Appearance and Behaviors and if they get corrupted or you want to use them on another computer, you can export the current settings and then import them onto another computer so that you don’t have to go through the same steps again.

  1. Go to File > Export Settings and in the Export Setting dialog box that appears choose the settings you want to export by clicking on the checkboxes.

    TIP: You can also click on the Select All or Select None buttons to select and then deselect the settings you want to save.

  2. In the Export setting to text field, provide a path to where you want the settings to be saved (e.g., /User/Cornelius/Desktop/setting.jar) and then click the OK button.

    TIP: You can change the extension on the settings.jar to settings.zip to see the files structure.

  3. In the Export Complete dialog box click the Reveal in Finder (Mac) or Reveal in Explorer (PC) button to go the folder the setting is located in.
  4. Close the current project and delete the preference folder (e.g., AndriodStudioPreview).
  5. Restart Android Studio:
  6. In the Complete Installation dialog box that appears, you could import the setting from a previous version of Android that you currently have installed or you could import from a custom location. However, we want to use the third option to manual import the settings.
  7. CHECK POINT: You should now see the Welcome screen because Android Studio does not have preferences or settings file to work with.  And if you click the select the default option for all of the prompts and then click the Finish button, Android Studio will open the welcome screen. Open an existing Android Studio project and open an *.java file. You should see that all of your settings (e.g., font, method dividers) are gone.
  8. Select File > Import Settings… and then navigate to the import file. If you placed it on the desktop, select:
  9. Select the settings.jar file and then click the OK button.
  10. In the Select Components to import dialog box that appears, select the settings that you want to import.

    TIP: You can also click on the Select All or Select None and then click to select or deselect a setting.

  11. Then, click the OK button.
  12. In the Restart Needed dialog box that appears, click, the OK button to restart Android Studio.
  13. CHECKP POINT: Go back to the *.java file and you should see your settings restored.

Import Eclipse with ADT

To import a project from Eclipse with ADT (Android Developer Tools), once you import the project, you will need to make some configuration changes to the build.gradle file to make is compatible with a current version of Android Studio.

  1. From the Android Studio’s Welcome screen, click on the Import project (Eclipse ADT, Gradle, etc) link from the list and navigate to the project and then  click the OK button
  2. In the Import Project from ADT (Eclipse Android) dialog box that appears, click the Next button.
  3. On the next screen, keep all of the default checkbox options and then click the Finish button to import the project.
  4. CHECK POINT: In the Message panel that appears, you may see that the project failed because it failed to find target with hast string ‘android-XX’ in …/Android/sdk where XX is the version that the app was created with.
    TIP: To find out what Android version that corresponds to, open up the SDK Manager and look at the version level next to the API level. (e.g., Android  4.2 (Jelly Bean)  is API 17). You could download that API level but it is better to upgrade to the new API level explained next.
  5. Open the Project window and navigate to the app module and click on the build.gradle file to open it.
  6. Change:
    1. compileSdkVersion and targetSdkVersion  to the latest version (e.g., 17  to 23)
    2. compile dependencies to the latest version(s) (e.g., ….support-v4:23.0.0).
      NOTE: You may get a warning that the support library might not be installed. Click the Try Again link at the top of the screen to sync the gradle file with the project. You may also see a message at the bottom of the screen informing you that there is a more recent version of the support library. Change it to the latest version (e.g., ….support-v4:23.2.0) and then click the Sync Now link.
  7. CHECK POINT: You should not see any warnings or errors. Run the app on your device to see if it works properly.