blob: 40c17ed14d5c3f428cbedc4be1bb80b0ef77e1a3 [file] [log] [blame]
Scott Main3f41d8f2011-02-08 18:46:23 -08001page.title=Managing Projects from Eclipse with ADT
Scott Main9cf2fa02011-02-15 18:26:07 -08002parent.title=Managing Projects
3parent.link=index.html
Robert Lybf6c3382010-12-22 11:05:10 -08004@jd:body
5
6 <div id="qv-wrapper">
7 <div id="qv">
8 <h2>In this document</h2>
9
10 <ol>
11 <li><a href="#CreatingAProject">Creating an Android Project</a></li>
12
13 <li><a href="#SettingUpLibraryProject">Setting up a Library Project</a></li>
14
15 <li><a href="#ReferencingLibraryProject">Referencing a Library Project</a></li>
16 </ol>
17
18 <h2>See also</h2>
19
20 <ol>
21 <li><a href=
22 "{@docRoot}guide/developing/testing/testing_eclipse.html#CreateTestProjectEclipse">Testing
Scott Main300cd262011-02-08 15:04:42 -080023 from Eclipse with ADT</a></li>
Robert Lybf6c3382010-12-22 11:05:10 -080024 </ol>
25 </div>
26 </div>
27
28 <p>Eclipse and the ADT plugin provide GUIs and wizards to create all three types of projects
29 (Android project, Library project, and Test project):
30
31 <ul>
32 <li>An Android project contains all of the files and resources that are needed to build a project into
33 an .apk file for installation. You need to create an Android project for any application that you
34 want to eventually install on a device.</li>
35
36 <li>You can also designate an Android project as a library project, which allows it to be shared
37 with other projects that depend on it. Once an Android project is designated as a library
38 project, it cannot be installed onto a device.</li>
39
40 <li>Test projects extend JUnit test functionality to include Android specific functionality. For
41 more information on creating a test project, see <a href=
Scott Main300cd262011-02-08 15:04:42 -080042 "{@docRoot}guide/developing/testing/testing_eclipse.html">Testing from Eclipse with ADT</a>.</li>
Robert Lybf6c3382010-12-22 11:05:10 -080043 </ul>
44
45 <h2 id="CreatingAProject">Creating an Android Project</h2>
46
47 <p>The ADT plugin provides a <em>New Project Wizard</em> that you can use to quickly create a new Android
48 project (or a project from existing code). To create a new project:</p>
49
50 <ol>
51 <li>Select <strong>File</strong> &gt; <strong>New</strong> &gt; <strong>Project</strong>.</li>
52
53 <li>Select <strong>Android</strong> &gt; <strong>Android Project</strong>, and click
54 <strong>Next</strong>.</li>
55
56 <li>Select the contents for the project:
57
58 <ul>
59 <li>Enter a <em>Project Name</em>. This will be the name of the folder where your project
60 is created.</li>
61
62 <li>Under Contents, select <strong>Create new project in workspace</strong>. Select your
63 project workspace location.</li>
64
65 <li>Under Target, select an Android target to be used as the project's Build Target. The
66 Build Target specifies which Android platform you'd like your application built against.
67
68 <p>Select the lowest platform with which your application is compatible.</p>
69
70 <p class="note"><strong>Note:</strong> You can change your the Build Target for your
71 project at any time: Right-click the project in the Package Explorer, select
72 <strong>Properties</strong>, select <strong>Android</strong> and then check the desired
73 Project Target.</p>
74 </li>
75
76 <li>Under Properties, fill in all necessary fields.
77
78 <ul>
79 <li>Enter an <em>Application name</em>. This is the human-readable title for your
80 application &mdash; the name that will appear on the Android device.</li>
81
82 <li>Enter a <em>Package name</em>. This is the package namespace (following the same
83 rules as for packages in the Java programming language) where all your source code will
84 reside.</li>
85
86 <li>Select <em>Create Activity</em> (optional, of course, but common) and enter a name
87 for your main Activity class.</li>
88
89 <li>Enter a <em>Min SDK Version</em>. This is an integer that indicates the minimum API
90 Level required to properly run your application. Entering this here automatically sets
91 the <code>minSdkVersion</code> attribute in the <a href=
92 "{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</a> of your
93 Android Manifest file. If you're unsure of the appropriate <a href=
94 "{@docRoot}guide/appendix/api-levels.html">API Level</a> to use, copy the API Level
95 listed for the Build Target you selected in the Target tab.</li>
96 </ul>
97 </li>
98 </ul>
99 </li>
100
101 <li>Click <strong>Finish</strong>.</li>
102 </ol>
103
104 <p class="note"><strong>Tip:</strong> You can also start the New Project Wizard from the
105 <em>New</em> icon in the toolbar.</p>
106
107 <h2 id="SettingUpLibraryProject">Setting up a Library Project</h2>
108
109 <p>A library project is a standard Android project, so you can create a new one in the same way
110 as you would a new application project.</p>
111
112 <p>When you are creating the library project, you can select any application name, package, and
113 set other fields as needed, as shown in figure 1.</p>
114
115 <p>Next, set the project's properties to indicate that it is a library project:</p>
116
117 <ol>
118 <li>In the <strong>Package Explorer</strong>, right-click the library project and select
119 <strong>Properties</strong>.</li>
120
121 <li>In the <strong>Properties</strong> window, select the "Android" properties group at left
122 and locate the <strong>Library</strong> properties at right.</li>
123
124 <li>Select the "is Library" checkbox and click <strong>Apply</strong>.</li>
125
126 <li>Click <strong>OK</strong> to close the <em>Properties</em> window.</li>
127 </ol>
128
129 <p>The new project is now marked as a library project. You can begin moving source code and
130 resources into it, as described in the sections below.</p>
131
132 <p>You can also convert an existing application project into a library. To do so, simply open the
133 Properties for the project and select the "is Library" checkbox. Other application projects can
134 now reference the existing project as a library project.</p>
135
136 <img src= "{@docRoot}images/developing/adt-props-isLib.png">
137
138 <p class="img-caption"><strong>Figure 1.</strong> Marking a project as an
139 Android library project.</p>
140
141 <h3>Creating the manifest file</h3>
142
143 <p>A library project's manifest file must declare all of the shared components that it includes,
144 just as would a standard Android application. For more information, see the documentation for
145 <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>.</p>
146
147 <p>For example, the <a href=
148 "{@docRoot}resources/samples/TicTacToeLib/AndroidManifest.html">TicTacToeLib</a> example library
149 project declares the Activity <code>GameActivity</code>:</p>
150 <pre>
151&lt;manifest&gt;
152 ...
153 &lt;application&gt;
154 ...
155 &lt;activity android:name="GameActivity" /&gt;
156 ...
157 &lt;/application&gt;
158&lt;/manifest&gt;
159</pre>
160
161 <h2 id="ReferencingLibraryProject">Referencing a library project</h2>
162
163 <p>If you are developing an application and want to include the shared code or resources from a
164 library project, you can do so easily by adding a reference to the library project in the
165 application project's Properties.</p>
166
167 <p>To add a reference to a library project, follow these steps:</p>
168
169 <ol>
170 <li>In the <strong>Package Explorer</strong>, right-click the dependent project and select
171 <strong>Properties</strong>.</li>
172
173 <li>In the <strong>Properties</strong> window, select the "Android" properties group at left
174 and locate the <strong>Library</strong> properties at right.</li>
175
176 <li>Click <strong>Add</strong> to open the <strong>Project Selection</strong> dialog.</li>
177
178 <li>From the list of available library projects, select a project and click
179 <strong>OK</strong>.</li>
180
181 <li>When the dialog closes, click <strong>Apply</strong> in the <strong>Properties</strong>
182 window.</li>
183
184 <li>Click <strong>OK</strong> to close the <strong>Properties</strong> window.</li>
185 </ol>
186
187 <p>As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents
188 of the library project.</p>
189
190 <p>Figure 2 shows the Properties dialog that lets you add library references and move
191 them up and down in priority.</p><img src="{@docRoot}images/developing/adt-props-libRef.png">
192
193 <p class="img-caption"><strong>Figure 2.</strong> Adding a reference to a
194 library project in the properties of an application project.</p>
195
196 <p>If you are adding references to multiple libraries, note that you can set their relative
197 priority (and merge order) by selecting a library and using the <strong>Up</strong> and
198 <strong>Down</strong> controls. The tools merge the referenced libraries with your application
199 starting from lowest priority (bottom of the list) to highest (top of the list). If more than one
200 library defines the same resource ID, the tools select the resource from the library with higher
201 priority. The application itself has highest priority and its resources are always used in
202 preference to identical resource IDs defined in libraries.</p>
203
204 <h3>Declaring library components in the the manifest file</h3>
205
206 <p>In the manifest file of the application project, you must add declarations of all components
207 that the application will use that are imported from a library project. For example, you must
208 declare any <code>&lt;activity&gt;</code>, <code>&lt;service&gt;</code>,
209 <code>&lt;receiver&gt;</code>, <code>&lt;provider&gt;</code>, and so on, as well as
210 <code>&lt;permission&gt;</code>, <code>&lt;uses-library&gt;</code>, and similar elements.</p>
211
212 <p>Declarations should reference the library components by their fully-qualified package names,
213 where appropriate.</p>
214
215 <p>For example, the <a href=
216 "{@docRoot}resources/samples/TicTacToeMain/AndroidManifest.html">TicTacToeMain</a> example
217 application declares the library Activity <code>GameActivity</code> like this:</p>
218 <pre>
219&lt;manifest&gt;
220 ...
221 &lt;application&gt;
222 ...
223 &lt;activity android:name="com.example.android.tictactoe.library.GameActivity" /&gt;
224 ...
225 &lt;/application&gt;
226&lt;/manifest&gt;
227</pre>
228
229 <p>For more information about the manifest file, see the documentation for <a href=
230 "{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>.</p>
231
232
233
234
235
236
237