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