xref: /aosp_15_r20/sdk/docs/howto_use_cupcake_sdk.txt (revision 1789df15502f1991eff51ff970dce5df8404dd56)
1*1789df15SXin LiSubject: How to build use a Cupcake Android SDK & ADT Eclipse plugin.
2*1789df15SXin LiDate:    2009/03/27
3*1789df15SXin Li
4*1789df15SXin Li
5*1789df15SXin LiTable of content:
6*1789df15SXin Li  0- License
7*1789df15SXin Li  1- Foreword
8*1789df15SXin Li  2- Installation steps
9*1789df15SXin Li  3- For Eclipse users
10*1789df15SXin Li  4- For Ant users
11*1789df15SXin Li  5- Targets, AVDs, Emulator changes
12*1789df15SXin Li  6- Conclusion
13*1789df15SXin Li
14*1789df15SXin Li
15*1789df15SXin Li
16*1789df15SXin Li----------
17*1789df15SXin Li0- License
18*1789df15SXin Li----------
19*1789df15SXin Li
20*1789df15SXin Li Copyright (C) 2009 The Android Open Source Project
21*1789df15SXin Li
22*1789df15SXin Li Licensed under the Apache License, Version 2.0 (the "License");
23*1789df15SXin Li you may not use this file except in compliance with the License.
24*1789df15SXin Li You may obtain a copy of the License at
25*1789df15SXin Li
26*1789df15SXin Li      http://www.apache.org/licenses/LICENSE-2.0
27*1789df15SXin Li
28*1789df15SXin Li Unless required by applicable law or agreed to in writing, software
29*1789df15SXin Li distributed under the License is distributed on an "AS IS" BASIS,
30*1789df15SXin Li WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31*1789df15SXin Li See the License for the specific language governing permissions and
32*1789df15SXin Li limitations under the License.
33*1789df15SXin Li
34*1789df15SXin Li
35*1789df15SXin Li
36*1789df15SXin Li-----------
37*1789df15SXin Li1- Foreword
38*1789df15SXin Li-----------
39*1789df15SXin Li
40*1789df15SXin LiThis explains how to use the "new" SDK provided starting with cupcake.
41*1789df15SXin LiThe new SDK has as a different structure than the pre-cupcake ones.
42*1789df15SXin Li
43*1789df15SXin LiThis means:
44*1789df15SXin Li- The new SDK does not work with older Eclipse plugins (ADT 0.8)
45*1789df15SXin Li- The old SDKs (1.0 and 1.1) do NOT work with this Eclipse plugin (ADT 0.9)
46*1789df15SXin Li
47*1789df15SXin Li
48*1789df15SXin Li
49*1789df15SXin Li----------------------
50*1789df15SXin Li2- Installation steps
51*1789df15SXin Li----------------------
52*1789df15SXin Li
53*1789df15SXin LiFirst you will need to grab the zip of the SDK for your platform or build it
54*1789df15SXin Liyourself. Please refer to the accompanying document "howto_build_SDK.txt" if
55*1789df15SXin Lineeded.
56*1789df15SXin Li
57*1789df15SXin LiUnzip the SDK somewhere. We'll call that directory "SDK" in command-line
58*1789df15SXin Liexamples.
59*1789df15SXin Li
60*1789df15SXin LiGrab the new ADT Eclipse plugin zip file or build it yourself. Keep it
61*1789df15SXin Lisomewhere (no need to unzip).
62*1789df15SXin Li
63*1789df15SXin Li
64*1789df15SXin Li
65*1789df15SXin Li--------------------
66*1789df15SXin Li3- For Eclipse users
67*1789df15SXin Li--------------------
68*1789df15SXin Li
69*1789df15SXin Li
70*1789df15SXin LiBelow we'll explain how you can upgrade your Eclipse install to the new plugin.
71*1789df15SXin LiIf you already have a working Eclipse installation with a pre-0.9 ADT,
72*1789df15SXin Lianother suggestion is to simply install a new copy of Eclipse and create a
73*1789df15SXin Linew empty workspace. This is just a precaution. The update process should
74*1789df15SXin Libe otherwise harmless.
75*1789df15SXin Li
76*1789df15SXin Li
77*1789df15SXin Li
78*1789df15SXin LiA- Setting up Eclipse
79*1789df15SXin Li---------------------
80*1789df15SXin Li
81*1789df15SXin Li- You must have Eclipse 3.3 or 3.4. Eclipse 3.2 is not longer supported.
82*1789df15SXin Li
83*1789df15SXin Li  There are many flavors, or "editions", of Eclipse. To develop, we'd recommend
84*1789df15SXin Li  the "Java" edition. The "RCP" one is totally suitable too. The J2EE one is
85*1789df15SXin Li  probably overkill.
86*1789df15SXin Li
87*1789df15SXin Li
88*1789df15SXin Li- If updating an existing Eclipse, use Help > Software Update and please
89*1789df15SXin Li  uninstall the two features of the previous ADT: the "editors" feature and the
90*1789df15SXin Li  ADT feature itself.
91*1789df15SXin Li
92*1789df15SXin Li  => If you don't you will get a conflict on editors when installing
93*1789df15SXin Li     the new one.
94*1789df15SXin Li
95*1789df15SXin Li- Using Help > Software Update, add a new "archived site", point it to the new
96*1789df15SXin Li  adt.zip (e.g. android-eclipse-<some-id>.zip), select the "Install" button at
97*1789df15SXin Li  the top right and restart eclipse as needed.
98*1789df15SXin Li
99*1789df15SXin Li- After it restarts, please use Window > Preferences > Android and select
100*1789df15SXin Li  the new SDK folder that you unzipped in paragraph 2.
101*1789df15SXin Li
102*1789df15SXin Li
103*1789df15SXin Li
104*1789df15SXin LiB- Updating older projects
105*1789df15SXin Li--------------------------
106*1789df15SXin Li
107*1789df15SXin LiIf you have pre-0.9 projects in your Eclipse workspace, or if you import them
108*1789df15SXin Lifrom your code repository, these projects will fail to build at first.
109*1789df15SXin Li
110*1789df15SXin LiFirst right-click on the project and select "Properties":
111*1789df15SXin Li
112*1789df15SXin Li- In the properties, open the Android panel and select the platform to use.
113*1789df15SXin Li  The SDK comes with a 1.5 platform. Select it and close the properties panel.
114*1789df15SXin Li- Do a clean build.
115*1789df15SXin Li
116*1789df15SXin Li
117*1789df15SXin LiThe new plugin creates a "gen" folder in your project where it puts the R.java
118*1789df15SXin Liand all automatically generated AIDL java files. If you get an error such as:
119*1789df15SXin Li
120*1789df15SXin Li  "The type R is already defined"
121*1789df15SXin Li
122*1789df15SXin Lithat means you must check to see if your old R.java or your old auto-generated
123*1789df15SXin LiAIDL Java files are still present in the "src" folder. If yes, remove them.
124*1789df15SXin Li
125*1789df15SXin LiNote: this does not apply to your own hand-crafted parcelable AIDL java files.
126*1789df15SXin Li
127*1789df15SXin LiNote: if you want to reuse the project with an older Eclipse ADT install,
128*1789df15SXin Li      simply remove the "gen" folder from the build path of the project.
129*1789df15SXin Li
130*1789df15SXin Li
131*1789df15SXin LiC- New Wizards
132*1789df15SXin Li--------------
133*1789df15SXin Li
134*1789df15SXin LiThe "New Android Project" wizard has been expanded to use the multi-platform
135*1789df15SXin Licapabilities of the new SDK.
136*1789df15SXin Li
137*1789df15SXin LiThere is now a "New XML File" wizard that lets you create skeleton XML resource
138*1789df15SXin Lifiles for your Android projects. This makes it easier to create a new layout, a
139*1789df15SXin Linew strings file, etc.
140*1789df15SXin Li
141*1789df15SXin LiBoth wizard are available via File > New... as well as new icons in the main
142*1789df15SXin Liicon bar. If you do not see the new icons, you may need to use Window > Reset
143*1789df15SXin LiPerspective on your Java perspective.
144*1789df15SXin Li
145*1789df15SXin Li
146*1789df15SXin LiPlease see step 5 "Emulator changes" below for important details on how to run
147*1789df15SXin Lithe emulator.
148*1789df15SXin Li
149*1789df15SXin Li
150*1789df15SXin Li
151*1789df15SXin Li----------------
152*1789df15SXin Li4- For Ant users
153*1789df15SXin Li----------------
154*1789df15SXin Li
155*1789df15SXin Li
156*1789df15SXin LiA- build.xml has changed
157*1789df15SXin Li------------------------
158*1789df15SXin Li
159*1789df15SXin LiYou must re-create your build.xml file.
160*1789df15SXin Li
161*1789df15SXin LiFirst if you had customized your build.xml, make a copy of it:
162*1789df15SXin Li
163*1789df15SXin Li  $ cd my-project
164*1789df15SXin Li  $ cp build.xml build.xml.old
165*1789df15SXin Li
166*1789df15SXin Li
167*1789df15SXin LiThen use the new "android" tool to create a new build.xml:
168*1789df15SXin Li
169*1789df15SXin Li  $ SDK/tools/android update project --path /path/to/my-project
170*1789df15SXin Li
171*1789df15SXin Lior
172*1789df15SXin Li
173*1789df15SXin Li  $ cd my-project
174*1789df15SXin Li  $ SDK/tools/android update project --path .
175*1789df15SXin Li
176*1789df15SXin Li
177*1789df15SXin LiA "gen" folder will be created the first time you build and your R.java and
178*1789df15SXin Liyour AIDL Java files will be generated in this "gen" folder. You MUST remove
179*1789df15SXin Lithe old R.java and old auto-generated AIDL java files manually. (Note: this
180*1789df15SXin Lidoes not apply to your own hand-crafted parcelabe AIDL java files.)
181*1789df15SXin Li
182*1789df15SXin Li
183*1789df15SXin LiB- Where is activitycreator?
184*1789df15SXin Li----------------------------
185*1789df15SXin Li
186*1789df15SXin LiNote that the "activitycreator" tool has been replaced by the new "android"
187*1789df15SXin Litool too. Example of how to create a new Ant project:
188*1789df15SXin Li
189*1789df15SXin Li  $ SDK/tools/android create project --path /path/to/my/project --name ProjectName
190*1789df15SXin Li      --package com.mycompany.myapp --activity MyActivityClass
191*1789df15SXin Li      --target 1 --mode activity
192*1789df15SXin Li
193*1789df15SXin Li
194*1789df15SXin LiPlease see paragraph 5 below for important details on how to run the emulator
195*1789df15SXin Liand the meaning of that "--target 1" parameter.
196*1789df15SXin Li
197*1789df15SXin Li
198*1789df15SXin Li
199*1789df15SXin Li----------------------------------
200*1789df15SXin Li5- Targets, AVDs, Emulator changes
201*1789df15SXin Li----------------------------------
202*1789df15SXin Li
203*1789df15SXin LiThis applies to BOTH Eclipse and Ant users.
204*1789df15SXin Li
205*1789df15SXin LiOne major change with the emulator is that now you must pre-create an "Android
206*1789df15SXin LiVirtual Device" (a.k.a "AVD") before you run the emulator.
207*1789df15SXin Li
208*1789df15SXin Li
209*1789df15SXin Li
210*1789df15SXin LiA- What is an AVD and why do I need one?
211*1789df15SXin Li----------------------------------------
212*1789df15SXin Li
213*1789df15SXin LiWhat is an "AVD"? If you forget, just run:
214*1789df15SXin Li
215*1789df15SXin Li  $ SDK/tools/emulator -help-virtual-device
216*1789df15SXin Li
217*1789df15SXin Li  An Android Virtual Device (AVD) models a single virtual device running the
218*1789df15SXin Li  Android platform that has, at least, its own kernel, system image and data
219*1789df15SXin Li  partition.
220*1789df15SXin Li
221*1789df15SXin LiThere is a lot more explanation given by the emulator. Please run the help
222*1789df15SXin Licommand given above to read the rest.
223*1789df15SXin Li
224*1789df15SXin LiThe bottom line is that you can create many emulator configurations, or "AVDs",
225*1789df15SXin Lieach with their own system image and most important each with their own user
226*1789df15SXin Lidata and SD card data. Then you tell Eclipse or the emulator which one to use
227*1789df15SXin Lito debug or run your applications.
228*1789df15SXin Li
229*1789df15SXin Li
230*1789df15SXin LiNote for Eclipse users: eventually there will be a user interface to do all of
231*1789df15SXin Lithese operations. For right now, please use the command line interface.
232*1789df15SXin Li
233*1789df15SXin Li
234*1789df15SXin LiB- Listing targets and AVDs
235*1789df15SXin Li---------------------------
236*1789df15SXin Li
237*1789df15SXin LiThere is a new tool called "android" in the SDK that lets you know which
238*1789df15SXin Li"target" and AVDs you can use.
239*1789df15SXin Li
240*1789df15SXin LiA target is a specific version of Android that you can use. By default the SDK
241*1789df15SXin Licomes with an "Android 1.5" target, codenamed "cupcake". In the future there
242*1789df15SXin Liwill be more versions of Android to use, e.g. "Android 2.0" or specific add-ons
243*1789df15SXin Liprovided by hardware manufacturers. When you want to run an emulator, you need
244*1789df15SXin Lito specify a given flavor of Android: this is the "target".
245*1789df15SXin Li
246*1789df15SXin Li
247*1789df15SXin LiTo learn about available targets in your SDK, use this command:
248*1789df15SXin Li
249*1789df15SXin Li  $ SDK/tools/android list targets
250*1789df15SXin Li
251*1789df15SXin LiThis will give you an output such as:
252*1789df15SXin Li
253*1789df15SXin Li  Available Android targets:
254*1789df15SXin Li  [1] Android 1.5
255*1789df15SXin Li       API level: 3
256*1789df15SXin Li       Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
257*1789df15SXin Li
258*1789df15SXin LiNote the "[1]". Later you will need to reference this as "--target 1" on the
259*1789df15SXin Licommand line.
260*1789df15SXin Li
261*1789df15SXin Li
262*1789df15SXin LiSimilarly you can list the available AVDs:
263*1789df15SXin Li
264*1789df15SXin Li  $ SDK/tools/android list avds
265*1789df15SXin Li
266*1789df15SXin LiWhich might output something as:
267*1789df15SXin Li
268*1789df15SXin Li  Available Android Virtual Devices:
269*1789df15SXin Li      Name: my_avd
270*1789df15SXin Li      Path: C:\Users\<username>\.android\avd\my_avd.avd
271*1789df15SXin Li    Target: Android 1.5 (API level 3)
272*1789df15SXin Li      Skin: 320x480
273*1789df15SXin Li    Sdcard: 16M
274*1789df15SXin Li
275*1789df15SXin Li
276*1789df15SXin Li
277*1789df15SXin LiC- Creating an AVD
278*1789df15SXin Li------------------
279*1789df15SXin Li
280*1789df15SXin LiTo create a configuration:
281*1789df15SXin Li
282*1789df15SXin Li  $ SDK/tools/android create avd --name my_avd_name --target 1
283*1789df15SXin Li
284*1789df15SXin Li
285*1789df15SXin Liwhere "target 1" is the index of a target listed by "android list targets".
286*1789df15SXin Li
287*1789df15SXin LiThe AVD name is purely an identifier used to refer to the AVD later.
288*1789df15SXin LiSince it is used as directory name, please avoid using shell or path specific
289*1789df15SXin Licharacters.
290*1789df15SXin Li
291*1789df15SXin LiTo learn the various options available when creating an AVD, simply type:
292*1789df15SXin Li
293*1789df15SXin Li  $ SDK/tools/android create avd
294*1789df15SXin Li
295*1789df15SXin LiThe android tool will automatically print an explanation of required arguments.
296*1789df15SXin Li
297*1789df15SXin Li
298*1789df15SXin Li
299*1789df15SXin LiD- Invoking an AVD from the command-line
300*1789df15SXin Li----------------------------------------
301*1789df15SXin Li
302*1789df15SXin LiTo use this AVD in the emulator from the command-line, type:
303*1789df15SXin Li
304*1789df15SXin Li  $ SDK/tools/emulator @my_avd_name
305*1789df15SXin Li
306*1789df15SXin Li
307*1789df15SXin LiFor more options, please consult the emulator help:
308*1789df15SXin Li
309*1789df15SXin Li  $ SDK/tools/emulator -help-virtual-device
310*1789df15SXin Li
311*1789df15SXin Li
312*1789df15SXin Li
313*1789df15SXin LiE- Invoking an AVD from Eclipse
314*1789df15SXin Li-------------------------------
315*1789df15SXin Li
316*1789df15SXin LiBy default Android projects in Eclipse have an "automatic target" mode.
317*1789df15SXin LiIn this mode, when a project is deployed in debug or run, it checks:
318*1789df15SXin Li- If there's one running device or emulator, this is used for deployment.
319*1789df15SXin Li- If there's more than one running device or emulator, a "device chooser" is
320*1789df15SXin Li  shown to let the user select which one to use.
321*1789df15SXin Li- If there are no running devices or emulators, ADT looks at available AVDs.
322*1789df15SXin Li  If one matches the project configuration (e.g. same API level), it is
323*1789df15SXin Li  automatically used.
324*1789df15SXin Li
325*1789df15SXin LiAlternatively you can edit the "launch configuration" on your Android project
326*1789df15SXin Liin Eclipse by selecting the menu Run > Run Configurations. In the "target" tab
327*1789df15SXin Liof the configuration, you can choose:
328*1789df15SXin Li
329*1789df15SXin Li- Manual or automatic targetting mode.
330*1789df15SXin Li
331*1789df15SXin Li  - Manual means to always present the device chooser.
332*1789df15SXin Li  - Automatic is the behavior explained above.
333*1789df15SXin Li
334*1789df15SXin Li- In automatic mode, which AVD is preferred. If none is selected, the first
335*1789df15SXin Li  suitable is used.
336*1789df15SXin Li
337*1789df15SXin Li
338*1789df15SXin LiF- AVD concurrency
339*1789df15SXin Li------------------
340*1789df15SXin Li
341*1789df15SXin LiYou can no longer run several emulators at the same time on the same
342*1789df15SXin Liconfiguration.
343*1789df15SXin Li
344*1789df15SXin LiBefore this used to put the second or more emulators in a transient read-only
345*1789df15SXin Limode that would not save user data.
346*1789df15SXin Li
347*1789df15SXin LiNow you just need to create as many AVDs as you want to run emulators.
348*1789df15SXin Li
349*1789df15SXin LiFor example if you are working on a client/server application for Android, you
350*1789df15SXin Licould create a "client" AVD and a "server" AVD then run them both at once. The
351*1789df15SXin Liemulator window will show you the AVD name so that you know which one is which.
352*1789df15SXin Li
353*1789df15SXin LiExample:
354*1789df15SXin Li
355*1789df15SXin Li  $ SDK/tools/android create avd --name client --target 1 --sdcard 16M --skin HVGA
356*1789df15SXin Li  $ SDK/tools/android create avd --name server --target 1 --sdcard 32M --skin HVGA-P
357*1789df15SXin Li  $ SDK/tools/emulator @server &
358*1789df15SXin Li  $ SDK/tools/emulator @client &
359*1789df15SXin Li
360*1789df15SXin Li
361*1789df15SXin Li
362*1789df15SXin Li-------------
363*1789df15SXin Li6- Conclusion
364*1789df15SXin Li-------------
365*1789df15SXin Li
366*1789df15SXin LiThis completes the howto guide on how to use the new Cupcake SDK.
367*1789df15SXin LiFeedback is welcome on the public Android Open Source forums:
368*1789df15SXin Li  http://source.android.com/community
369*1789df15SXin Li
370*1789df15SXin Li-end-
371*1789df15SXin Li
372