Thursday 25 July 2013

Installing of Android SDK

How to Install Android SDK

NOTE: Installing all the necessary software needed for Android programming takes times - It could take hours?!
Pre-Installation Check List
Before installing Android SDK, you need to install:
  1. Java Development Kit (JDK): Read "How to install JDK".
  2. Eclipse: Read "How to install Eclipse".

Now, you are ready to install the Android SDK.
Step 0: Read the "Android Training"
Start from Android's mother site @ http://www.android.com.
Goto "Developers" @ http://developer.android.com. There are three main menus: Design, Develop, and Distribute. Start with "Develop", you can find the "Android Training", "API Guides", "Reference" and "Tools". For beginners, browse through the "Android Training".
Step 1: Download the Android SDK
Download the Android SDK from http://developer.android.com/sdk/index.html. For novices, choose the installer version by clicking the button "Download the SDK for Windows" (installer_r20-windows.exe). For Lunix and Mac, select "Other Platforms".
For advanced programmers, I recommend that you choose the ZIP version (under the "Other Platforms") (android-sdk_r20-windows.zip). I prefer the ZIP version, as you could install many versions, rename the directory, and remove the installation easily.
Step 2: Install Android SDK
Run the downloaded installer into a directory of your choice, e.g., "d:\bin\android-sdk"; or unizp the downloaded ZIP file. Take note of the installed directory. Hereafter, I shall denote the android installed directory as <ANDROID_SDK_HOME>.
Step 3: Install Android Platforms and Add-ons via "SDK Manager"
The Android SDK comprises 2 parts: the "tools" and the "Platforms & Add-ons". After running the installer (in the pervious step), the basic "tools" are installed, which are executables that support app development. The "Platforms & Add-ons" consist of ALL Android platforms (from Android 1.x to 4.x) and various Google Add-ons (such as Google Map API), which could be selectively installed.
Now, we have to choose our Android "Platforms & Add-ons".
  1. Launch Android's "SDK Manager", which is responsible for managing the software components. If you have run the installer, it should have started the SDK Manager after the installation. Otherwise, launch the SDK manager by running (double-clicking) "SDK Manager.exe" under the Android installed directory.
  2. In "Add Platforms and Packages", select your target Android platforms and add-ons packages. For novices, select "Android SDK Platform-Tools", and at least one Android platform (e.g., Android 4.1 (API 16)) ⇒ "Install".
Step 4: Install Eclipse Android Development Tool (ADT) Plugin
I suppose that you have installed Eclipse.
  1. Launch Eclipse.
  2. Install Eclipse ADT: From Eclipse's "Help" menu ⇒ "Install New Software..." ⇒ In "Work with", enter https://dl-ssl.google.com/android/eclipse/ ⇒ Check ALL boxes ⇒ Next ⇒ Finish ⇒ Restart Eclipse to use ADT plugin.
  3. Configure Eclipse ADT: From Eclipse's "Window" menu ⇒ Preferences ⇒ Android ⇒ In "SDK Location", select the Android SDK installed directory (e.g., "d:\bin\android-sdk").
Step 5: Create a Android Virtual Device (AVD) (or Emulator) via "AVD Manager"
AVDs are emulators that allow you to test your application without the real devices. You can create AVDs for different android platforms (from Android 1.x to Android 4.x) and configurations (e.g., screen size, orientation, SD card and its capacity).
  1. From Eclipse's "Window" menu ⇒ Preferences ⇒ Android ⇒ In "SDK Location", enter your Android SDK installed directory (e.g., "d:\bin\android-sdk").
  2. From "Window" menu ⇒ AVD Manager. (You could also start the AVD manager by running "AVD Manager.exe" under the Android SDK installed directory.)
  3. In "Android Virtual Device Manager" dialog ⇒ "New".
  4. The "Create New Android Virtual Device (AVD)" dialog appears. In "Name", enter "Android41_Phone". Select the "Target" Android platform, "SD Card Size" (e.g., 10MB, do not set a huge SD Card size, which would take hours to create.) Skin (screen resolution, e.g., WVGA800x480 for smart phone - Wiki "Graphics display resolution" for the various resolution) ⇒ "Create AVD".
You can test your AVD by launching the emulator. Start the AVD manager ⇒ Select a AVD ⇒ Click the "Start" button ⇒ Check "Scale display to real size" to get a smaller screen that could fit in your display ⇒ Launch. Wait patiently! The emulator is very slow and take a few MINUTES to launch. You can change the orientation (between portrait and landscape) of the the emulator via "Ctrl-F11".
We typically create different AVDs to emulate different real devices, e.g., Android41_tablet of resolution (1024x768 XGA).
Step 6: Setup PATH
You can skip this step now if you are not familiar with PATH, but it is needed later.
Include the android's tools directory (<ANDROID_SDK_HOME>\tools) and platform-tools directory (<ANDROID_SDK_HOME>\platform-tools) to your PATH environment variable.
For Windows: Start "Control Panel" ⇒ "System" ⇒ (Vista/7) "Advanced system settings" ⇒ Switch to "Advanced" tab ⇒ "Environment variables" ⇒ Choose "System Variables" for all users (or "User Variables" for this login user only) ⇒ Select variable "PATH" ⇒ Choose "Edit" for modifying an existing variable ⇒ In variable "Value", APPEND your <ANDROID_SDK_HOME>\tools directory (e.g., "d:\bin\android-sdk\tools"), followed by a semi-colon ';'IN FRONT of all the existing path entries. DO NOT remove any existing entry; otherwise, some programs may not run.
Add the platform-tools directory to the PATH too.

3.  Write your First Android Program Using Eclipse ADT

Android apps are written in Java, and use XML extensively. I shall assume that you have basic knowledge of Java programming and XML.

3.1  Hello-world

Step 0: Read
Go to "Android Training" @ http://developer.android.com/training/index.html, Read "Get Started", "Build your first app".
Step 1: Create a new Android Project
  1. Launch Eclipse.
  2. From "File" menu ⇒ New ⇒ Project.. ⇒ Android Application Project ⇒ Next.
  3. The "New Android Project" dialog appears:
    1. In "Application Name", enter "Hello Android" (this is the Android appliation name that shows up on the real device).
    2. In "Project Name", enter "HelloAndroid" (this is the Eclipse's project name).
    3. In "Package Name", enter "com.example.helloandroid".
    4. In "Build SDK", select the latest version (e.g., Android 4.1 (API 16)).
    5. In "Minimum Required SDK", select "API 8 Android 2.2 (Froyo)" - almost all of the Android devices meet this minimum requirement ⇒ Next.
  4. The "Configure Launcher Icon" dialog appears, which allows you to set the application's icon to be displayed on the devices ⇒ Next.
  5. The "Create Activitiy" dialog appears. Check "Create Activity" Box ⇒ Select "BlankActivity" ⇒ Next.
  6. The "New Blank Activity" dialog appears.
    1. In "Activity Name", enter "HelloActivity".
    2. In "Layout Name", enter "activity_hello" (default).
    3. In "Title", enter "Hello" (this title will appear as the screen title) ⇒ Finish.
Eclipse ADT creates a default Hello-world Android app.
Step 2: Run the Android App
Run the application by right-click on the project node ⇒ "Run As" ⇒ "Android Application".
Be patient! It takes a few MINUTES to fire up the emulator! Watch the Eclipse's status bar for the launching progress; and the console view (or LogCat view) for messages.
Once the emulator started, unlock the device by holding and sweeping the "lock" to the right (or left). It shall launch your Hello-world app, and displays "Hello, world!" on the screen with a title "Hello".
If your program is not launched automatically, try launching it from the "app menu" manually, after the emulator is started. Look for the icon "Hello".

Trying launching the app from "HOME" ⇒ "..." ⇒ Look for the icon "Hello".
Also try "HOME" ⇒ "..." ⇒ "MENU" ⇒ "Manage Apps" ⇒ Select "HelloAndroid" ⇒ Uninstall.

NOTE: DO NOT CLOSE the emulator, as it really takes a long time to start. You could always re-run or run new applications on the same emulator.
Run the Android App on Real Devices
To run the Andriod app on the real devices:
  1. Connect the real device to your computer. Make sure that you have the "USB Driver" for your device installed on your computer. You can find the "Google USB Driver" @http://developer.android.com/sdk/win-usb.html, and Google's certified "OEM USB Drivers" @ http://developer.android.com/tools/extras/oem-usb.html. If you device is not certified there, good luck! It took me many hours to find a compatible driver for my cheap Pad.
  2. Enable "USB Debugging" mode on your real device: 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 Eclipse, right-click on the project node ⇒ Run As ⇒ Android Application.
  5. The "Android Device Chooser" dialog appears. Select your real device (instead of the AVD emulator) ⇒ OK.
  6. Eclipse ADT installs the app on the connected device and starts it.
You can also use the "adb" (Android Debug Bridge) tool (under "<ANDROID_SDK_HOME>\platform-tools") to install the ".apk" file ("HelloAndroid.apk") onto the real devices:
// Change directory to <project-root>\bin, where the ".apk" is located
// -d option for real device
> adb -d install filename.apk
2402 KB/s (157468 bytes in 0.064s)
        pkg: /data/local/tmp/filename.apk
Success
  
> adb --help

No comments:

Post a Comment