Bogotobogo
contact@bogotobogo.com

Bookmark and Share


Android Logo



Android 4.0
1. Introduction







1.1 What is Android?

Android is an operating system based on Linux with a Java programming interface, targeted at mobile hardware such as phones and tablet computers. It seems that it keeps increasing market share in smartphone and even trying to get footing into TV world (Google TV with Android OS). It provides tools, e.g. a compiler, debugger and a device emulator as well as its own Java Virtual machine (Dalvik). Android is created by the Open Handset Alliance which is lead by Google.
Android uses a special Java virtual machine (Dalvik) which is based on the Apache Harmony Java implementation. Dalvik uses special bytecode there you cannot run standard Java program on Android but you have to use the Android compiler to create this special byte-code.

Android_OS_Linux_Kernel

Your Ad Here


Android supports 2-D and 3-D graphics using the OpenGL libraries and supports data storage in a SQLLite database.
For development Google provides the Android Development Tools (ADT) for Eclipse to develop Android applications.
Android's Linux kernel-based OS doesn't come with a sophisticated shell environment, but because the platform is open, we can write and install shells on a device.


Android Versions

Android platform releases 1 through 2 are aimed primarily at smartphone devices, whereas Android release 3 will be the first operating platform specifically designed with high-end support for tablet computers.

The API level targeted by our application is important for device compatibility and the software development.


Android Versions


1.2 What do we need to develop Android applications?

  • JDK (version 6 or 7 required).
    We should have a recent version of the Java SDK (JDK) installed on our system.
    To see what compatible version of the JDK is installed, do a quick check on the command line as below:
    $ java -version
    java version "1.7.0_02"
    Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)
    
    $ javac -version
    javac 1.7.0_01
    
    Now, Java platform is ready to go.

  • Eclipse IDE for Java Developers (version 3.6-Helios or 3.7-Indigo).



  • Base Android SDK
    We now need to download the Android SDK starter package and use it to install our target Android platforms.
    Download the Android SDK from the Android homepage. The download contains a zip file which you can extract to any place in your file system, e.g. I placed it under "C:\apps\android-sdk-windows".
    The Android SDK archive only contains the tools, and we need to use the SDK Manager to install or update SDK components such as platforms, tools, etc. We must install at least one version of the Android platform using the SDK Manager in order to start developing applications.



  • Android Development Tools (ADT)
    Intalling using Eclipse Update Manager as shown in the next section of this tutorial is much easier.



1.3 Setting up Android Development Tools (ADT)

Use the update manager of Eclipse to install all available plugins for the Android Development Tools (ADT).

From Elicpse, Help->Install New Software



Available_Software.png

In the Available Software dialog, click Add. Then, type in "Android Plugin" in the Name field and URL "https://dl-ssl.google.com/android/eclipse/" in the Location field.


Add_Site.png

Then, hit OK.


Added_google_android.png

Hit OK, again and select the checkbox next to Developer Tools. Then, the nested tools Android DDMS and Android Development Tools will be selected automatically.


Developer_Tools_Android_DDMS.png

In the Install Details dialog, the Android DDMS and Android Development Tools features are listed.


Install_Details.png

Click Next.


Review_Licenses.png

Click Finish, and restart Eclipse.


Restart_Eclipse.png






1.4 Configuration

In Eclipse, open the Preferences dialog via Windows -> Preferences.
Select Android and type in the installation path of the Android SDK as the picture below.


Eclipse Android Preference

After hit Apply, we get:


EclipseAndroidPreferenceAfterApply.png

Hit OK after set the target.

Select Window -> Android SDK Manager from the menu.


Android SDK Manager

Install packages if needed.

(Note) We can also get the SDK Manager using following command:

$ android
or
$ "sdk manager.exe"



1.5 Device for Emulation - Android Virtual Devices (AVD)

For emulation, we need to define a device.
Select Window -> Android AVD Manager from the menu.


Virtual Device New Button

Press "New", then you are about to create a New AVD as the picture below.

Create New AVD

Hit "Create AVD" button.
Then you will have


AVD Created

To test if your setup is correct, select your device and press "Start".
Check the "Scale display to real size" at the Launch Options window below.


AVD Launch Options

At the Launch button, you will have the device, finally.


Test Device Picture




Default AVD Locations by OS
  • Linux and Mac OS X
    ~/.android/avd/
  • Windows XP
    C:\Documents and Settings\<user>\.android\avd\
  • Windows Vista
    C:\Users\<user>\.android\avd\



1.6 Android Development Kit Tools

Android SDK Development Tool Commands

Android SDK Development Tool Linux/Mac OS X Windows
Android SDK and AVD Manager android android.bat
Dalvik Debug Monitor ddms ddms.bat



1.7 Importing Project
  1. Open the import Dialog
    Select File > Import ... to open the import dialog.

  2. Import the "MyProject" project
    In the import dialog, expand the General node and select Existing Projects into Workspace, then click Next to move to the Import Projects step. Make sure that Select root directory is selected, then click the Browse... button.
    In the Browse For Folder dialog, locate the "MyProject" folder, select it and click OK. Then, click Finish to import the project. The project now shows up in the Package Explorer.

  3. Launch the "MyProject" project
    Right click the "MyProject" in the Package Explorer window, and then select Run As > Android Application from the menu.



1.8 Importing Project - @Override issue

When we have the following line of code from the imported package, depending on the compliance level, we may get error message from Eclipse:

      @Override
      public void onClick(DialogInterface dialog, int button)
      {

In my case, I got:

Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead.

since I'm using Java 1.7. In this case, we need to set the compliance level to 1.6 because 1.5 won't work with the @Override annotation. Right click on the Project -> Properties, then select Java Compiler, the set it 1.6 as in the picture below.


import_override_annotation

At Apply, we get:

Compiler_Setting_Changed

Hit "Yes", and that's it.



1.9 Deleting Project

Here is the project-wise solution. Right click the "MyProject" in the Package Explorer window, and then select Delete from the menu. In the dialog that appears, ensure that Delete project contents on disk is not selected if we want to use the project's folders in workspace. If not, we can check it before be click OK.






Full List of Android Tutorials