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