Build your first Android project

This tutorial information about developing your first project using Android Studio SDK software in MS Windows OS. See the steps below to develop your first Android app.

Step 1: Create a New Android Project
  1. Launch Android Studio.
  2. Choose “Start a new Android Studio Project”.
  3. In “Choose your project”, select “Phone and Tablet” tab ⇒ “Empty Activity” ⇒ Next.
  4. In “Configure your project” ⇒ Set “Name” to “Hello Android” (this will be the “Title” in your phone’s app menu) ⇒ The “Package name” and “Save Location” will be updated automatically ⇒ In “Language”, select “Java” ⇒ Leave the “Minimum API Level” and the rest to default ⇒ Finish.
  5. Be patient! It could take a few minutes to set up your first app. Watch the “progress bar” at the bottom status bar and wait for a while. Once the progress bar indicates completion, a hello-world app is created by default.
Step 2: Setup Emulator (i.e. Android Virtual Device or AVD)

To run your Android app under the emulator, you need to first create an Android Virtual Devices (AVD). An AVD models a specific device (e.g., your jPone or Taimi). You can create AVDs to emulate different android devices (e.g., phone/tablet, android version, screen size, and etc.).

  1. In Android studio, select “Tools” ⇒ Android ⇒ AVD Manager. See “Common Errors” below if you cannot find “AVD manager”.
  2. Click “Create Virtual Device”.
  3. In “Choose a device definition” ⇒ In “Category”, choose “Phone” ⇒ In “Name”, choose “2.7 QVGA” (the smallest device available – you can try a bigger device later) ⇒ Next.
  4. In “System Image: Recommended” ⇒ Select the version with the highest API level ⇒ Click “Download” ⇒ Next.
  5. In “AVD Name”, enter “2.7 QVGA API 27” (default) ⇒ Finish.
  6. If you see “VT-x is disabled in BIOS”: Check your BIOS setting to ensure that “Virtualization Technology” is enabled. Shutdown and re-boot your PC to enter the BIOS setup. This is machine dependent. Google “Your-PC-brand-and-model enter BIOS setup”. For example, for my HP computer ⇒ Boot ⇒ “ESC” to enter BIOS setup ⇒ Advanced ⇒ System Options ⇒ Check “Virtualization Technology (VTx)” ⇒ Save ⇒ Exit.
Step 3: Run the Android App on Emulator
  1. Select the “Run” menu ⇒ “Run app” ⇒ Under “Available Virtual Devices”, select “2.7 QVGA API 27” ⇒ OK.
  2. You MAY BE prompted to install Intel HAXM (Hardware Accelerated Execution Manager). Follow the instruction to install HAXM.
  3. Be patient! It may take a few MINUTES to fire up the app on the emulator. You first see a Google logo ⇒ then “Android” ⇒ then the “wallpaper” ⇒ then the “Hello, world!” message.
    If you have problem running on the emulator, I suggest you try to run on an actual Android device (phone/pad) if you have one. Goto next step.
  4. DO NOT CLOSE THE EMULATOR, as it really takes a long time to start. You could always re-run the app (or run a new app) on the same emulator. Try re-run the app by selecting “Run” menu ⇒ “Run app”.

Common possible errors:

  1. If everything fails, select “File” menu ⇒ “Invalidate Caches / Restart…” ⇒ and wait …
  2. Cannot find “AVD manager” in the “Tool” menu: You may not have enough packages needed for the project. You should have a window with Gradle alert with a link which you can click and you will see a window with a prompt to download missing packages. When all stuff downloaded the “ADV manager” should be enabled.
  3. If you get an error message “Fail to find target with hash string ‘android-26’“. Either click the link “Install missing platform(s) and sync project” to install API-26 (another GB download!); or Under “Gradle Scripts” ⇒ Open “build.gradle (Module: app)” ⇒ Change “compileSdkVersion” and “targetSdkVersion” from 26 to 27 (we have installed API-27) and “com.android.support:appcompat-v7:26.x.x” to “27.0.0“.
  4. If you get an error message “Re-download dependencies and sync project (requires network)”, click the link to download. If the message appears again:
    • (Windows) Goto “C:\Users\username\.gradle\wrapper\dists” and delete “gradle-x.x-all“. Take note the “.gradle” is a hidden directory and you need to enable viewing of hidden directory.
    • (Macs) Goto “~\.gradle\wrapper\dists” and delete “gradle-x.x-all“. Take note the “.gradle” is a hidden directory and you need to enable viewing of hidden directory.

    Restart Android Studio.
    This error is due to poor network condition, resulted in corrupted download.

  5. If you encountered error “Emulator: ERROR: x86 emulation currently requires hardware acceleration“, Read “https://stackoverflow.com/questions/29136173/emulator-error-x86-emulation-currently-requires-hardware-acceleration“, (6), and (7).
  6. If you encountered error “HAX is not working…” ⇒ Open “SDK Manager” ⇒ SDK Tools ⇒ Check if “Intel x86 Emulator Accelerator (HAXM Installer)” is installed ⇒ Goto SDK Location (by default, “C:\Users\your-username\AppData\Local\Android\Sdk\extras\intel\Hardware_Accelerated_Execution_Manager” for Windows or “~/Library/Android/sdk/extras/intel/Hardware_Accelerated_Execution_Manager” for Mac OS X) ⇒ run “intelhaxm-android.exe” to install HAXM ⇒ Be patient! The installer may take a while to launch ⇒ Follow the screen instructions to complete the setup.
    Take note that: (a) In Windows, the “AppData” directory is hidden. You need to unhide via “Control Panel” ⇒ “Folder Options” (or “File Explorer Options” in Windows 10) ⇒ Check “Show hidden files, folders, and drives”. (b) In Mac OS X, the “Library” folder is hidden. You can unhide via “Finder” ⇒ Go ⇒ Home ⇒ Settings ⇒ Show View Option.
    If the problem persists, remove and then re-install.
  7. If you encountered error “Intel virtualization technology (VT-x) is not turned on” ⇒ Check your BIOS setting to ensure that “Intel virtualization technology” is enabled. Shutdown and re-boot your PC to enter the BIOS setup. This is machine dependent. Google “Your-PC-brand-and-model enter BIOS setup”.
    If “Intel virtualization technology” is already enabled, this error is probably caused by your antivirus software. Disable your antivirus for this session and rerun.
    See http://stackoverflow.com/questions/21635504/error-during-installing-haxm-vt-x-not-working
  8. If you have problem creating AVD via “AVD Manager”, open the AVD manager via command line as follows:
    // For Windows
    cd C:\Users\your-username\AppData\Local\Android\sdk\tools
    android avd
Step 4: Run the Android App on Real Devices

To run the Android app on a REAL device (Android Phone or Tablet):

  1. Connect the real device to your computer. Make sure that you have the “USB Driver” for your device installed on your computer. If not, goto https://developer.android.com/studio/run/oem-usb.html to Install OEM USB Drivers. If you device is not certified there, then it is OK.
  2. Enable “USB Debugging” mode on your real device:
    (On Android 4.2/5.0 and newer) Need to enable “Developer options” via “Settings” ⇒ About Phone ⇒ Scroll to the bottom and tap “Build number” seven (7) times until “Developer Mode” is displayed. Return to the previous screen to find “Developer options” ⇒ Open “Developer options” ⇒ Enable “USB debugging”.
    (On Android 4.0) From “Settings” ⇒ “Developer options” ⇒ Check “USB Debugging”.
    (On Android 3.2 and older) From “Settings” ⇒ “Applications” ⇒ “Development” ⇒ Check “USB Debugging”.
    This allows Android SDK to transfer data between your computer and your device. Also enable “Unknown source” from “Applications”. This allows applications from unknown sources to be installed on the device.
  3. You shall see the message “USB Debugging Connected” when you plugs the USB cable into your computer.
  4. From Android Studio, select “Run” menu ⇒ “Run app” ⇒ Your device shall be listed under “Choose a running device” ⇒ Select the device ⇒ OK.
Deleting a Project

To delete a project, select “File” ⇒ “Close Project” ⇒ On the “Recent Projects” ⇒ Hover over the project ⇒ Press “Delete” key on the project to remove the project from Android Studio ⇒ You can then delete the project directory from the file system.