Home | History | Annotate | Download | only in projects
      1 page.title=Managing Projects from Eclipse with ADT
      2 parent.title=Managing Projects
      3 parent.link=index.html
      4 @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}tools/testing/testing_eclipse.html#CreateTestProjectEclipse">Testing
     23         from Eclipse with ADT</a></li>
     24       </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=
     42   "{@docRoot}tools/testing/testing_eclipse.html">Testing from Eclipse with ADT</a>.</li>
     43   </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
     48   Android 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 Application Project</strong>, and click
     54     <strong>Next</strong>.</li>
     55 
     56     <li>Enter the basic settings for the project:
     57 
     58       <ul>
     59         <li>Enter an <strong>Application Name</strong>. This name is used as the title of your
     60         application launcher icon when it is installed on a device.</li>
     61 
     62         <li>Enter a <strong>Project Name</strong>. This text is used as the name of the folder where
     63         your project is created.</li>
     64 
     65         <li>Enter a <strong>Package Name</strong>. This class package namespace creates the initial
     66         package structure for your applications code files and is added as the
     67         <a href="{@docRoot}guide/topics/manifest/manifest-element.html#package">{@code package}</a>
     68         attribute in your application's
     69         <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">Android manifest file</a>.
     70         This manifest value serves as the unique identifier for your application app when you
     71         distribute it to users. The package name must follow the same rules as packages in the Java
     72         programming language.</li>
     73 
     74         <li>Select a <strong>Minimum Required SDK</strong>. This setting indicates the lowest
     75         version of the Android platform that your application supports. This value sets the
     76         <code>minSdkVersion</code> attribute in the
     77         <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</a>
     78         element of your manifest file.</li>
     79 
     80         <li>Select a <strong>Target SDK</strong>. This setting indicates the highest version of
     81         Android with which you have tested with your application and sets the
     82         <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
     83         targetSdkVersion}</a> attribute in your application's' manifest file.
     84 
     85           <p class="note"><strong>Note:</strong> You can change the target SDK for your
     86           project at any time: Right-click the project in the Package Explorer, select
     87           <strong>Properties</strong>, select <strong>Android</strong> and then check the desired
     88           <strong>Project Build Target</strong>.</p>
     89         </li>
     90 
     91         <li>Select a <strong>Compile With</strong> API version. This setting specifies what version
     92         of the SDK to compile your project against. We strongly recommend using the most recent
     93         version of the API.</li>
     94 
     95         <li>Select a <strong>Theme</strong>. This setting specifies which standard Android
     96         <a href="{@docRoot}design/style/themes.html">visual style</a> is applied to your
     97         application.</li>
     98 
     99         <li>Click <strong>Next</strong>.</li>
    100       </ul>
    101     </li>
    102 
    103     <li>In the <strong>Configure Project</strong> page, select the desired settings and click
    104       <strong>Next</strong>. Leave the <strong>Create activity</strong> option checked so you can
    105       start your application with some essential components.</li>
    106 
    107     <li>In the <strong>Configure Launcher Icon</strong> page, create an icon and click
    108       <strong>Next</strong>.</li>
    109 
    110     <li>In the <strong>Create Activity</strong> page, select activity template and click
    111       <strong>Next</strong>. For more information about Android code templates, see
    112       <a href="{@docRoot}tools/projects/templates.html">Using Code Templates</a>.
    113       </li>
    114 
    115     <li>Click <strong>Finish</strong> and the wizard creates a new project according to the options
    116       you have chosen.</li>
    117   </ol>
    118 
    119   <p class="note"><strong>Tip:</strong> You can also start the New Project Wizard by clicking the
    120   <strong>New</strong> <img src="/images/tools/eclipse-new.png"
    121   style="vertical-align:baseline;margin:0"> icon in the toolbar.</p>
    122 
    123 
    124   <h2 id="SettingUpLibraryProject">Setting up a Library Project</h2>
    125 
    126   <p>A library project is a standard Android project, so you can create a new one in the same way
    127   as you would a new application project.</p>
    128 
    129   <p>To create a new library project:</p>
    130 
    131   <ol>
    132     <li>Select <strong>File</strong> &gt; <strong>New</strong> &gt; <strong>Project</strong>.</li>
    133 
    134     <li>Select <strong>Android</strong> &gt; <strong>Android Application Project</strong>, and click
    135     <strong>Next</strong>.</li>
    136 
    137     <li>Enter the basic settings for the project, including <strong>Application Name</strong>,
    138     <strong>Project Name</strong>, <strong>Package Name</strong>, and SDK settings.</li>
    139 
    140     <li>In the <strong>Configure Project</strong> page, select the <strong>Mark this project as a
    141     library</strong> option to flag the project as a library.</li>
    142 
    143     <li>Set the other options as desired and click <strong>Next</strong>.</li>
    144 
    145     <li>Follow the instructions to complete the wizard and create a new library project.</li>
    146   </ol>
    147 
    148   <p>You can also convert an existing application project into a library. To do so, simply open the
    149     Properties for the project and select the <strong>is Library</strong> checkbox, as shown in
    150     the figure below.</p>
    151 
    152   <img src= "{@docRoot}images/developing/adt-props-isLib.png">
    153   <p class="img-caption"><strong>Figure 1.</strong> Marking a project as an Android library.</p>
    154 
    155   <p>To set the a project's properties to indicate that it is a library project:</p>
    156 
    157   <ol>
    158     <li>In the <strong>Package Explorer</strong>, right-click the library project and select
    159     <strong>Properties</strong>.</li>
    160 
    161     <li>In the <strong>Properties</strong> window, select the <strong>Android</strong> properties
    162     group in the left pane and locate the <strong>Library</strong> properties in the right pane.</li>
    163 
    164     <li>Select the <strong>is Library</strong> check box and click <strong>Apply</strong>.</li>
    165 
    166     <li>Click <strong>OK</strong> to close the <strong>Properties</strong> window.</li>
    167   </ol>
    168 
    169   <p>Once you create a library project or mark an existing project as a library, you can reference
    170   the library project in other Android application projects. For more information, see the
    171   <a href="#ReferencingLibraryProject">Referencing a library project</a> section.
    172 
    173 
    174   <h3>Creating the manifest file</h3>
    175 
    176   <p>A library project's manifest file must declare all of the shared components that it includes,
    177   just as would a standard Android application. For more information, see the documentation for
    178   <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>.</p>
    179 
    180   <p>For example, the <a href=
    181   "{@docRoot}resources/samples/TicTacToeLib/AndroidManifest.html">TicTacToeLib</a> example library
    182   project declares the activity <code>GameActivity</code>:</p>
    183   <pre>
    184 &lt;manifest&gt;
    185   ...
    186   &lt;application&gt;
    187     ...
    188     &lt;activity android:name="GameActivity" /&gt;
    189     ...
    190   &lt;/application&gt;
    191 &lt;/manifest&gt;
    192 </pre>
    193 
    194   <h2 id="ReferencingLibraryProject">Referencing a library project</h2>
    195 
    196   <p>If you are developing an application and want to include the shared code or resources from a
    197   library project, you can do so easily by adding a reference to the library project in the
    198   application project's Properties.</p>
    199 
    200   <p>To add a reference to a library project, follow these steps:</p>
    201 
    202   <ol>
    203     <li>Make sure that both the project library and the application project that depends on it are
    204       in your workspace. If one of the projects is missing, import it into your workspace.</li>
    205 
    206     <li>In the <strong>Package Explorer</strong>, right-click the dependent project and select
    207     <strong>Properties</strong>.</li>
    208 
    209     <li>In the <strong>Properties</strong> window, select the "Android" properties group at left
    210     and locate the <strong>Library</strong> properties at right.</li>
    211 
    212     <li>Click <strong>Add</strong> to open the <strong>Project Selection</strong> dialog.</li>
    213 
    214     <li>From the list of available library projects, select a project and click
    215     <strong>OK</strong>.</li>
    216 
    217     <li>When the dialog closes, click <strong>Apply</strong> in the <strong>Properties</strong>
    218     window.</li>
    219 
    220     <li>Click <strong>OK</strong> to close the <strong>Properties</strong> window.</li>
    221   </ol>
    222 
    223   <p>As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents
    224   of the library project.</p>
    225 
    226   <p>Figure 2 shows the Properties dialog that lets you add library references and move
    227   them up and down in priority.</p><img src="{@docRoot}images/developing/adt-props-libRef.png">
    228 
    229   <p class="img-caption"><strong>Figure 2.</strong> Adding a reference to a
    230      library project in the properties of an application project.</p>
    231 
    232   <p>If you are adding references to multiple libraries, note that you can set their relative
    233   priority (and merge order) by selecting a library and using the <strong>Up</strong> and
    234   <strong>Down</strong> controls. The tools merge the referenced libraries with your application
    235   starting from lowest priority (bottom of the list) to highest (top of the list). If more than one
    236   library defines the same resource ID, the tools select the resource from the library with higher
    237   priority. The application itself has highest priority and its resources are always used in
    238   preference to identical resource IDs defined in libraries.</p>
    239 
    240   <h3>Declaring library components in the manifest file</h3>
    241 
    242   <p>In the manifest file of the application project, you must add declarations of all components
    243   that the application will use that are imported from a library project. For example, you must
    244   declare any <code>&lt;activity&gt;</code>, <code>&lt;service&gt;</code>,
    245   <code>&lt;receiver&gt;</code>, <code>&lt;provider&gt;</code>, and so on, as well as
    246   <code>&lt;permission&gt;</code>, <code>&lt;uses-library&gt;</code>, and similar elements.</p>
    247 
    248   <p>Declarations should reference the library components by their fully-qualified package names,
    249   where appropriate.</p>
    250 
    251   <p>For example, the <a href=
    252   "{@docRoot}resources/samples/TicTacToeMain/AndroidManifest.html">TicTacToeMain</a> example
    253   application declares the library activity <code>GameActivity</code> like this:</p>
    254   <pre>
    255 &lt;manifest&gt;
    256   ...
    257   &lt;application&gt;
    258     ...
    259     &lt;activity android:name="com.example.android.tictactoe.library.GameActivity" /&gt;
    260     ...
    261   &lt;/application&gt;
    262 &lt;/manifest&gt;
    263 </pre>
    264 
    265   <p>For more information about the manifest file, see the documentation for <a href=
    266   "{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>.</p>
    267 
    268 
    269 
    270 
    271 
    272 
    273 
    274