page.title=Managing Projects from Eclipse with ADT
parent.title=Managing Projects
parent.link=index.html
@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
        from 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 from Eclipse with ADT</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> &gt; <strong>New</strong> &gt; <strong>Project</strong>.</li>

    <li>Select <strong>Android</strong> &gt; <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 &mdash; 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">&lt;uses-sdk&gt;</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>
&lt;manifest&gt;
  ...
  &lt;application&gt;
    ...
    &lt;activity android:name="GameActivity" /&gt;
    ...
  &lt;/application&gt;
&lt;/manifest&gt;
</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>&lt;activity&gt;</code>, <code>&lt;service&gt;</code>,
  <code>&lt;receiver&gt;</code>, <code>&lt;provider&gt;</code>, and so on, as well as
  <code>&lt;permission&gt;</code>, <code>&lt;uses-library&gt;</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>
&lt;manifest&gt;
  ...
  &lt;application&gt;
    ...
    &lt;activity android:name="com.example.android.tictactoe.library.GameActivity" /&gt;
    ...
  &lt;/application&gt;
&lt;/manifest&gt;
</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>