Prepare For Android Development

Android OS is currently installed on more mobile devices than any other OS which makes is a very popular and lucrative platform to learn. Also, the Android OS can be installed on:

Except for the framework, an app's APK is composed of the following resources that you have complete control over:

These resources are compiled to build the app using a build system called Gadle Build

To test and enable an Android device for development requires several environments and settings to be setup. While these processes are tedious, most of them are one-time setup unless you have to upgrade to a newer version:

NOTE: If you are using HTML5, CSS3 and JavaScript to create an app using PhoneGap and you would like to test on a real device, you only need to do the last step (Test on Real Device(s)) and only the Test on Real Device with PhoneGap.

Google takes a very different approach to unlocking a device for development purposes from Apple. Android allows you to install and run apps that have not been digitally signed for public release (debug version). But in order to do so, you must first enable a setting on a device that is turned off by default on a real device. And since there are so many types of Android devices and versions of the Android OS, the exact instructions on how to set it might be different. If you're having trouble locating it, do a quick online search. The apps PhoneGap Build compiles for Android are actually assigned a debug key automatically. When an app is ready to release publicly it will need to be signed digitally with a personal key.

You don't have to use an IDE to create an app, you can use a Command Line Interface (CLI) using PhoneGap. However, it is easier to use a free IDE like Android Studio from Google that has replaced Eclipse as the tool of choose. Android Studio is based on the Java development environment called IntelliJ IDEA created by JetBrains and is available for Windows, Mac OS X and Linux.

Configure Environment

Now that you know how to navigate the Android Studio project structure, you will want to configure certain aspects of it to control the appearance and behavior of Android Studio.

Go to File > Settings... (CTRL+ALT+S) on Windows and go to the Android Studio menu and select Preferences (CMD + ,) on the Mac.

Check For Updates

You should check every now-and-then for updates to ensure you have the latest version.

  1. Open Android Studio and click the Help > Check for Updates Now link.
  2. If there's a newer version available, you can update and restart immediately.

    NOTE: It is important to note that there are multiple channels for updates. The Stable Channel is the default. However, you can change it to another channel. To get the latest version that have not be fully tested, change to the Canary Channel.The Canary Channel will offer early beta software that may not have been fully tested but has new features and improvements. After a few days of testing, it will be promoted to the Beta Channel.

  3. Click the Configure button and then on Windows, click on Settings and on Mac, click on Preferences.
  4. Click on the Updates option to change to another channel.

    NOTE: On Windows, you might be prompted with the User Account Control dialog box. And on Mac, you might need to type in your administrative password.

  5. Restart Android Studio.

Another place to check for updates in in the SDK Manager.

  1. Open the SDK Manager:
    • From the Welcome screen, click on the Configure > SDK Manager from the bottom of the window..
    • From the menu, select Tools > Android > SDK Manager.
    • From the of the window, select the SDK Manager icon.
  2. Use the SDK Platforms tab to download different versions of the Android SDK. Each API level corresponds to an Android version (e.g., Android 6 (Marshmellow) refers to API Level 23). The minimum API Level the is set by default is Android 4.0.3 (IceCreamSandwich) or API Level 15 so you will need to download that version as well.

Integrating Source Control

Android Studio also provide ways to integrate with many source control packages (e.g., CVS, Subversion, git) via add-ons which allow it to manage checking out files, etc.  However, not all files are suitable for source control (e.g., files in the bin and gen directories). 

To exclude these files add some extension to the exclusion list (e.g., *.apx, *.ap_, *.dex). ????

Import Sample Apps

Another way to test and learn how to use Android Studio is to import sample apps.

  1. Open Android Studio, go to File > New > Import Sample... and select a sample from the list and then click the Next button.

    NOTE: You can click the browse the source in GitHub link to view the source files. You will have to install Git on your computer if you don't already have it installed or go DIRECTLY to GitHub and clikc on the Download zip file to download the file from there.

  2. Accept the defaults and then click the Next button.

    NOTE: Many samples may use a older version of the Android Build Tools. You could update the Gradle file to the latest version or click the link at the bottom of the screen and follow the prompts, click the Accept radio button and then click the Next button to download the needed Build Tools.

  3. In the Configure Sample dialog box that appears, accept the defaults and then click the Finish button and return to Android Studio.
  4. In the Language Level Changed dialog box, you will be prompted to reload the project, so click the Yes button.
  5. Click the Run button and choose a virtual device and then click the OK button.
  6. CHECK POINT: You should see the app load in the virtual device.
  7. (Optional) Return to Android Studio and examine the files that were created from the sample app.