2011-02-08 18:46:23 -08:00
|
|
|
page.title=Managing Projects from Eclipse with ADT
|
2011-02-15 18:26:07 -08:00
|
|
|
parent.title=Managing Projects
|
|
|
|
parent.link=index.html
|
2010-12-22 11:05:10 -08:00
|
|
|
@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=
|
2012-06-21 17:14:39 -07:00
|
|
|
"{@docRoot}tools/testing/testing_eclipse.html#CreateTestProjectEclipse">Testing
|
2011-02-08 15:04:42 -08:00
|
|
|
from Eclipse with ADT</a></li>
|
2010-12-22 11:05:10 -08:00
|
|
|
</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):
|
2012-11-16 16:10:52 -08:00
|
|
|
|
2010-12-22 11:05:10 -08:00
|
|
|
<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=
|
2012-06-21 17:14:39 -07:00
|
|
|
"{@docRoot}tools/testing/testing_eclipse.html">Testing from Eclipse with ADT</a>.</li>
|
2010-12-22 11:05:10 -08:00
|
|
|
</ul>
|
|
|
|
|
|
|
|
<h2 id="CreatingAProject">Creating an Android Project</h2>
|
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<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>
|
2010-12-22 11:05:10 -08:00
|
|
|
|
|
|
|
<ol>
|
|
|
|
<li>Select <strong>File</strong> > <strong>New</strong> > <strong>Project</strong>.</li>
|
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Select <strong>Android</strong> > <strong>Android Application Project</strong>, and click
|
2010-12-22 11:05:10 -08:00
|
|
|
<strong>Next</strong>.</li>
|
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Enter the basic settings for the project:
|
2010-12-22 11:05:10 -08:00
|
|
|
|
|
|
|
<ul>
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Enter an <strong>Application Name</strong>. This name is used as the title of your
|
|
|
|
application launcher icon when it is installed on a device.</li>
|
|
|
|
|
|
|
|
<li>Enter a <strong>Project Name</strong>. This text is used as the name of the folder where
|
|
|
|
your project is created.</li>
|
|
|
|
|
|
|
|
<li>Enter a <strong>Package Name</strong>. This class package namespace creates the initial
|
|
|
|
package structure for your applications code files and is added as the
|
|
|
|
<a href="{@docRoot}guide/topics/manifest/manifest-element.html#package">{@code package}</a>
|
|
|
|
attribute in your application's
|
|
|
|
<a href="{@docRoot}guide/topics/manifest/manifest-intro.html">Android manifest file</a>.
|
|
|
|
This manifest value serves as the unique identifier for your application app when you
|
|
|
|
distribute it to users. The package name must follow the same rules as packages in the Java
|
|
|
|
programming language.</li>
|
|
|
|
|
|
|
|
<li>Select a <strong>Minimum Required SDK</strong>. This setting indicates the lowest
|
|
|
|
version of the Android platform that your application supports. This value sets the
|
|
|
|
<code>minSdkVersion</code> attribute in the
|
|
|
|
<a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><uses-sdk></a>
|
|
|
|
element of your manifest file.</li>
|
|
|
|
|
|
|
|
<li>Select a <strong>Target SDK</strong>. This setting indicates the highest version of
|
|
|
|
Android with which you have tested with your application and sets the
|
|
|
|
<a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
|
|
|
|
targetSdkVersion}</a> attribute in your application's' manifest file.
|
|
|
|
|
|
|
|
<p class="note"><strong>Note:</strong> You can change the target SDK for your
|
2010-12-22 11:05:10 -08:00
|
|
|
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
|
2012-11-16 16:10:52 -08:00
|
|
|
<strong>Project Build Target</strong>.</p>
|
2010-12-22 11:05:10 -08:00
|
|
|
</li>
|
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Select a <strong>Compile With</strong> API version. This setting specifies what version
|
|
|
|
of the SDK to compile your project against. We strongly recommend using the most recent
|
|
|
|
version of the API.</li>
|
2010-12-22 11:05:10 -08:00
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Select a <strong>Theme</strong>. This setting specifies which standard Android
|
|
|
|
<a href="{@docRoot}design/style/themes.html">visual style</a> is applied to your
|
|
|
|
application.</li>
|
2010-12-22 11:05:10 -08:00
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Click <strong>Next</strong>.</li>
|
2010-12-22 11:05:10 -08:00
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>In the <strong>Configure Project</strong> page, select the desired settings and click
|
|
|
|
<strong>Next</strong>. Leave the <strong>Create activity</strong> option checked so you can
|
|
|
|
start your application with some essential components.</li>
|
|
|
|
|
|
|
|
<li>In the <strong>Configure Launcher Icon</strong> page, create an icon and click
|
|
|
|
<strong>Next</strong>.</li>
|
|
|
|
|
|
|
|
<li>In the <strong>Create Activity</strong> page, select activity template and click
|
|
|
|
<strong>Next</strong>. For more information about Android code templates, see
|
|
|
|
<a href="{@docRoot}tools/projects/templates.html">Using Code Templates</a>.
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>Click <strong>Finish</strong> and the wizard creates a new project according to the options
|
|
|
|
you have chosen.</li>
|
2010-12-22 11:05:10 -08:00
|
|
|
</ol>
|
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<p class="note"><strong>Tip:</strong> You can also start the New Project Wizard by clicking the
|
|
|
|
<strong>New</strong> <img src="/images/tools/eclipse-new.png"
|
|
|
|
style="vertical-align:baseline;margin:0"> icon in the toolbar.</p>
|
|
|
|
|
2010-12-22 11:05:10 -08:00
|
|
|
|
|
|
|
<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>
|
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<p>To create a new library project:</p>
|
|
|
|
|
|
|
|
<ol>
|
|
|
|
<li>Select <strong>File</strong> > <strong>New</strong> > <strong>Project</strong>.</li>
|
|
|
|
|
|
|
|
<li>Select <strong>Android</strong> > <strong>Android Application Project</strong>, and click
|
|
|
|
<strong>Next</strong>.</li>
|
2010-12-22 11:05:10 -08:00
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Enter the basic settings for the project, including <strong>Application Name</strong>,
|
|
|
|
<strong>Project Name</strong>, <strong>Package Name</strong>, and SDK settings.</li>
|
|
|
|
|
|
|
|
<li>In the <strong>Configure Project</strong> page, select the <strong>Mark this project as a
|
|
|
|
library</strong> option to flag the project as a library.</li>
|
|
|
|
|
|
|
|
<li>Set the other options as desired and click <strong>Next</strong>.</li>
|
|
|
|
|
|
|
|
<li>Follow the instructions to complete the wizard and create a new library project.</li>
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
<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 <strong>is Library</strong> checkbox, as shown in
|
|
|
|
the figure below.</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.</p>
|
|
|
|
|
|
|
|
<p>To set the a project's properties to indicate that it is a library project:</p>
|
2010-12-22 11:05:10 -08:00
|
|
|
|
|
|
|
<ol>
|
|
|
|
<li>In the <strong>Package Explorer</strong>, right-click the library project and select
|
|
|
|
<strong>Properties</strong>.</li>
|
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>In the <strong>Properties</strong> window, select the <strong>Android</strong> properties
|
|
|
|
group in the left pane and locate the <strong>Library</strong> properties in the right pane.</li>
|
2010-12-22 11:05:10 -08:00
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Select the <strong>is Library</strong> check box and click <strong>Apply</strong>.</li>
|
2010-12-22 11:05:10 -08:00
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Click <strong>OK</strong> to close the <strong>Properties</strong> window.</li>
|
2010-12-22 11:05:10 -08:00
|
|
|
</ol>
|
|
|
|
|
2012-11-16 16:10:52 -08:00
|
|
|
<p>Once you create a library project or mark an existing project as a library, you can reference
|
|
|
|
the library project in other Android application projects. For more information, see the
|
|
|
|
<a href="#ReferencingLibraryProject">Referencing a library project</a> section.
|
2010-12-22 11:05:10 -08:00
|
|
|
|
|
|
|
|
|
|
|
<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
|
2012-11-16 16:10:52 -08:00
|
|
|
project declares the activity <code>GameActivity</code>:</p>
|
2010-12-22 11:05:10 -08:00
|
|
|
<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>
|
2012-11-16 16:10:52 -08:00
|
|
|
<li>Make sure that both the project library and the application project that depends on it are
|
|
|
|
in your workspace. If one of the projects is missing, import it into your workspace.</li>
|
|
|
|
|
2010-12-22 11:05:10 -08:00
|
|
|
<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>
|
|
|
|
|
2012-02-24 09:05:00 -08:00
|
|
|
<h3>Declaring library components in the manifest file</h3>
|
2010-12-22 11:05:10 -08:00
|
|
|
|
|
|
|
<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
|
2012-11-16 16:10:52 -08:00
|
|
|
application declares the library activity <code>GameActivity</code> like this:</p>
|
2010-12-22 11:05:10 -08:00
|
|
|
<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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|