jueves, 17 de noviembre de 2011

Install Android SDK 4.0 for development (ADT + Eclipse)


3. Installation

The following assume that you have already Eclipse installed. For details please see Eclipse Tutorial .

3.1. Eclipse and automatic Android SDK

Use the Eclipse update manager to install all available components for the Android Development Tools (ADT) from the URL https://dl-ssl.google.com/android/eclipse/ . If you are not familiar with the Eclipse update manager the usage is described in Eclipse update manager .
After the new Android development components are installed you will be prompted to install the Android SDK. You can do follow the following wizard or go to the next section to learn how to do it manually.

Wizard to install Android SDK - Part 1


Wizard to install Android SDK - Part 2


Wizard to install Android SDK - Part 3

3.2. Manually install Android SDK

The previous step downloads the Android SDK automatically for you. You can also download the Android SDK manuallz from the Android homepage under Android SDK download . The download contains a zip file which you can extract to any place in your file system, e.g. I placed it under "c:\android-sdk-windows". Avoid using spaces in the path name otherwise you may experience problems later.
You also have to define the location of the Android SDK in the Eclipse Preferences. In Eclipse open the Preferences dialog via Windows → Preferences . Select Android and enter the installation path of the Android SDK.

Setting up the Android SDK in the Eclipse Preferences

3.3. Install a specific Android version

The Android SDK Manager allows you to install specific versions of Android. Select Window → Android SDK Manager from the Eclipse menu.

Starting ADV Manager

The dialog allows you to install new package and also allow you to delete them. Select "Available packages" and open the "Third Party Add-ons". Select the Google API 14 (Android 4.0) version of the SDK and press "Install".

Install Android API

Press the "Install" button and confirm the license for all package. After the installation restart Eclipse.

3.4. Android Source Code

The following step is optional.
During Android development it is very useful to have the Android source code available as Android uses a lot of defaults.
Haris Peco maintains plugins which provides access to the Android Source code code. Use the Eclipse update manager to install the Android Source plugin from the following update site: "http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update".
More details can be found on the project website .

4. Emulator Shortcuts

4.1. Create an Android Emulator Device

The Android tools include an emulator. This emulator behaves like a real Android device in most cases and allows you to test your application without having a real device. You can emulate one or several devices with different configurations. Each configuration is defined via an "Android Virtual Device" (AVD).
To define an AVD open the "AVD Manager" via Windows → AVD Manager and press "New".

Create a new AVD

Enter the following.

Settings for a new AVD

We can also select the box "Enabled" for Snapshots. This will make the second start of the virtual device much faster.
At the end press the button "Create AVD".This will create the device and display it under the "Virtual devices". To test if your setup is correct, select your device and press "Start".
After (a long time) your device should be started.

4.2. Using the emulator

Obviously you can use the emulator via the keyboard on the right side of the emulator. But there are also some nice shortcuts which are useful.
Alt+Enter maximizes the emulator. Nice for demos.
Ctrl+F11 changes the orientation of the emulator.
F8 turns network on / off.

4.3. Performance

Try to use a smaller resolution for your emulator as for example HVGA. The emulator gets slower the more pixels its needs to render as it is using software rendering.
Also if you have sufficient memory on your computer, add at least 1 GB of memory to your emulator. This is the value "Device ram size" during the creation of the AVD.
Also set the flag "Enabled" for Snapshots. This will save the state of the emulator and let it start much faster.

5. Error handling and typical problems

Things are not always working as they should. This section gives an overview over typical problems and how to solve them.

5.1. Clean Project

Several users report that get the following errors:
  1. Project ... is missing required source folder: 'gen'
  2. The project could not be built until build path errors are resolved.
  3. Unable to open class file R.java.

To solve any of these errors, go to the project menu and select Project -> Clean.

5.2. LogCat

The LogCat view shows you the log message of your Android device and help you analyzing problems. For example Java exceptions in your program would be shown here. To open this view, select "Window -> Show View -> Other -> Android -> LogCat" from the menu.

5.3. Emulator does not start

If your emulator does not start, make sure that the androd-sdk version is in a path without any spaces in the path name.

5.4. Error message for @override

The @override annotation was introduced in Java 1.6. If you receive an error message for @override change the Java compiler level to Java 1.6 via right-mouse click on the project -> Properties -> Java Compiler -> Compiler compliance level and set it to "1.6".

5.5. Missing Imports

Java requires that the classes which are not part of the standard Java Language are either fully qualified or declared via imports. In your editor use the click mouse click, select "Source-> Organize Imports" if you see error message with "XX cannot be resolved to a variable".

5.6. Eclipse Tips

To work more efficient with Eclipse, select Window -> Preferences -> Java -> Editor -> Save Actions and select that the source code should be formated and that the imports should be organized at every save.

No hay comentarios:

Publicar un comentario