1 Subject: How to build use a Cupcake Android SDK & ADT Eclipse plugin.
11 5- Targets, AVDs, Emulator changes
20 Copyright (C) 2009 The Android Open Source Project
22 Licensed under the Apache License, Version 2.0 (the "License");
23 you may not use this file except in compliance with the License.
24 You may obtain a copy of the License at
26 http://www.apache.org/licenses/LICENSE-2.0
28 Unless required by applicable law or agreed to in writing, software
29 distributed under the License is distributed on an "AS IS" BASIS,
30 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 See the License for the specific language governing permissions and
32 limitations under the License.
40 This explains how to use the "new" SDK provided starting with cupcake.
41 The new SDK has as a different structure than the pre-cupcake ones.
44 - The new SDK does not work with older Eclipse plugins (ADT 0.8)
45 - The old SDKs (1.0 and 1.1) do NOT work with this Eclipse plugin (ADT 0.9)
49 ----------------------
51 ----------------------
53 First you will need to grab the zip of the SDK for your platform or build it
54 yourself. Please refer to the accompanying document "howto_build_SDK.txt" if
57 Unzip the SDK somewhere. We'll call that directory "SDK" in command-line
60 Grab the new ADT Eclipse plugin zip file or build it yourself. Keep it
61 somewhere (no need to unzip).
70 Below we'll explain how you can upgrade your Eclipse install to the new plugin.
71 If you already have a working Eclipse installation with a pre-0.9 ADT,
72 another suggestion is to simply install a new copy of Eclipse and create a
73 new empty workspace. This is just a precaution. The update process should
74 be otherwise harmless.
81 - You must have Eclipse 3.3 or 3.4. Eclipse 3.2 is not longer supported.
83 There are many flavors, or "editions", of Eclipse. To develop, we'd recommend
84 the "Java" edition. The "RCP" one is totally suitable too. The J2EE one is
88 - If updating an existing Eclipse, use Help > Software Update and please
89 uninstall the two features of the previous ADT: the "editors" feature and the
92 => If you don't you will get a conflict on editors when installing
95 - Using Help > Software Update, add a new "archived site", point it to the new
96 adt.zip (e.g. android-eclipse-<some-id>.zip), select the "Install" button at
97 the top right and restart eclipse as needed.
99 - After it restarts, please use Window > Preferences > Android and select
100 the new SDK folder that you unzipped in paragraph 2.
104 B- Updating older projects
105 --------------------------
107 If you have pre-0.9 projects in your Eclipse workspace, or if you import them
108 from your code repository, these projects will fail to build at first.
110 First right-click on the project and select "Properties":
112 - In the properties, open the Android panel and select the platform to use.
113 The SDK comes with a 1.5 platform. Select it and close the properties panel.
117 The new plugin creates a "gen" folder in your project where it puts the R.java
118 and all automatically generated AIDL java files. If you get an error such as:
120 "The type R is already defined"
122 that means you must check to see if your old R.java or your old auto-generated
123 AIDL Java files are still present in the "src" folder. If yes, remove them.
125 Note: this does not apply to your own hand-crafted parcelable AIDL java files.
127 Note: if you want to reuse the project with an older Eclipse ADT install,
128 simply remove the "gen" folder from the build path of the project.
134 The "New Android Project" wizard has been expanded to use the multi-platform
135 capabilities of the new SDK.
137 There is now a "New XML File" wizard that lets you create skeleton XML resource
138 files for your Android projects. This makes it easier to create a new layout, a
139 new strings file, etc.
141 Both wizard are available via File > New... as well as new icons in the main
142 icon bar. If you do not see the new icons, you may need to use Window > Reset
143 Perspective on your Java perspective.
146 Please see step 5 "Emulator changes" below for important details on how to run
156 A- build.xml has changed
157 ------------------------
159 You must re-create your build.xml file.
161 First if you had customized your build.xml, make a copy of it:
164 $ cp build.xml build.xml.old
167 Then use the new "android" tool to create a new build.xml:
169 $ SDK/tools/android update project --path /path/to/my-project
174 $ SDK/tools/android update project --path .
177 A "gen" folder will be created the first time you build and your R.java and
178 your AIDL Java files will be generated in this "gen" folder. You MUST remove
179 the old R.java and old auto-generated AIDL java files manually. (Note: this
180 does not apply to your own hand-crafted parcelabe AIDL java files.)
183 B- Where is activitycreator?
184 ----------------------------
186 Note that the "activitycreator" tool has been replaced by the new "android"
187 tool too. Example of how to create a new Ant project:
189 $ SDK/tools/android create project --path /path/to/my/project --name ProjectName
190 --package com.mycompany.myapp --activity MyActivityClass
191 --target 1 --mode activity
194 Please see paragraph 5 below for important details on how to run the emulator
195 and the meaning of that "--target 1" parameter.
199 ----------------------------------
200 5- Targets, AVDs, Emulator changes
201 ----------------------------------
203 This applies to BOTH Eclipse and Ant users.
205 One major change with the emulator is that now you must pre-create an "Android
206 Virtual Device" (a.k.a "AVD") before you run the emulator.
210 A- What is an AVD and why do I need one?
211 ----------------------------------------
213 What is an "AVD"? If you forget, just run:
215 $ SDK/tools/emulator -help-virtual-device
217 An Android Virtual Device (AVD) models a single virtual device running the
218 Android platform that has, at least, its own kernel, system image and data
221 There is a lot more explanation given by the emulator. Please run the help
222 command given above to read the rest.
224 The bottom line is that you can create many emulator configurations, or "AVDs",
225 each with their own system image and most important each with their own user
226 data and SD card data. Then you tell Eclipse or the emulator which one to use
227 to debug or run your applications.
230 Note for Eclipse users: eventually there will be a user interface to do all of
231 these operations. For right now, please use the command line interface.
234 B- Listing targets and AVDs
235 ---------------------------
237 There is a new tool called "android" in the SDK that lets you know which
238 "target" and AVDs you can use.
240 A target is a specific version of Android that you can use. By default the SDK
241 comes with an "Android 1.5" target, codenamed "cupcake". In the future there
242 will be more versions of Android to use, e.g. "Android 2.0" or specific add-ons
243 provided by hardware manufacturers. When you want to run an emulator, you need
244 to specify a given flavor of Android: this is the "target".
247 To learn about available targets in your SDK, use this command:
249 $ SDK/tools/android list targets
251 This will give you an output such as:
253 Available Android targets:
256 Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
258 Note the "[1]". Later you will need to reference this as "--target 1" on the
262 Similarly you can list the available AVDs:
264 $ SDK/tools/android list avds
266 Which might output something as:
268 Available Android Virtual Devices:
270 Path: C:\Users\<username>\.android\avd\my_avd.avd
271 Target: Android 1.5 (API level 3)
280 To create a configuration:
282 $ SDK/tools/android create avd --name my_avd_name --target 1
285 where "target 1" is the index of a target listed by "android list targets".
287 The AVD name is purely an identifier used to refer to the AVD later.
288 Since it is used as directory name, please avoid using shell or path specific
291 To learn the various options available when creating an AVD, simply type:
293 $ SDK/tools/android create avd
295 The android tool will automatically print an explanation of required arguments.
299 D- Invoking an AVD from the command-line
300 ----------------------------------------
302 To use this AVD in the emulator from the command-line, type:
304 $ SDK/tools/emulator @my_avd_name
307 For more options, please consult the emulator help:
309 $ SDK/tools/emulator -help-virtual-device
313 E- Invoking an AVD from Eclipse
314 -------------------------------
316 By default Android projects in Eclipse have an "automatic target" mode.
317 In this mode, when a project is deployed in debug or run, it checks:
318 - If there's one running device or emulator, this is used for deployment.
319 - If there's more than one running device or emulator, a "device chooser" is
320 shown to let the user select which one to use.
321 - If there are no running devices or emulators, ADT looks at available AVDs.
322 If one matches the project configuration (e.g. same API level), it is
325 Alternatively you can edit the "launch configuration" on your Android project
326 in Eclipse by selecting the menu Run > Run Configurations. In the "target" tab
327 of the configuration, you can choose:
329 - Manual or automatic targetting mode.
331 - Manual means to always present the device chooser.
332 - Automatic is the behavior explained above.
334 - In automatic mode, which AVD is preferred. If none is selected, the first
341 You can no longer run several emulators at the same time on the same
344 Before this used to put the second or more emulators in a transient read-only
345 mode that would not save user data.
347 Now you just need to create as many AVDs as you want to run emulators.
349 For example if you are working on a client/server application for Android, you
350 could create a "client" AVD and a "server" AVD then run them both at once. The
351 emulator window will show you the AVD name so that you know which one is which.
355 $ SDK/tools/android create avd --name client --target 1 --sdcard 16M --skin HVGA
356 $ SDK/tools/android create avd --name server --target 1 --sdcard 32M --skin HVGA-P
357 $ SDK/tools/emulator @server &
358 $ SDK/tools/emulator @client &
366 This completes the howto guide on how to use the new Cupcake SDK.
367 Feedback is welcome on the public Android Open Source forums:
368 http://source.android.com/community