• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Creating an Android Project
2parent.title=Building Your First App
3parent.link=index.html
4
5trainingnavtop=true
6next.title=Running Your App
7next.link=running-app.html
8
9@jd:body
10
11
12<!-- This is the training bar -->
13<div id="tb-wrapper">
14<div id="tb">
15
16<h2>This lesson teaches you to</h2>
17
18<ol>
19  <li><a href="#Eclipse">Create a Project with Eclipse</a></li>
20  <li><a href="#CommandLine">Create a Project with Command Line Tools</a></li>
21</ol>
22
23<h2>You should also read</h2>
24
25<ul>
26  <li><a href="{@docRoot}sdk/installing/index.html">Installing the
27SDK</a></li>
28  <li><a href="{@docRoot}tools/projects/index.html">Managing Projects</a></li>
29</ul>
30
31
32</div>
33</div>
34
35<p>An Android project contains all the files that comprise the source code for your Android
36app. The Android SDK tools make it easy to start a new Android project with a set of
37default project directories and files.</p>
38
39<p>This lesson
40shows how to create a new project either using Eclipse (with the ADT plugin) or using the
41SDK tools from a command line.</p>
42
43<p class="note"><strong>Note:</strong> You should already have the Android SDK installed, and if
44you're using Eclipse, you should have installed the <a
45href="{@docRoot}tools/sdk/eclipse-adt.html">ADT plugin</a> as well. If you have not installed
46these, see <a href="{@docRoot}sdk/installing/index.html">Installing the Android SDK</a> and return here
47when you've completed the installation.</p>
48
49
50<h2 id="Eclipse">Create a Project with Eclipse</h2>
51
52<div class="figure" style="width:416px">
53<img src="{@docRoot}images/training/firstapp/adt-firstapp-setup.png" alt="" />
54<p class="img-caption"><strong>Figure 1.</strong> The new project wizard in Eclipse.</p>
55</div>
56
57<ol>
58  <li>In Eclipse, select <strong>File &gt; New &gt; Project</strong>.
59The resulting dialog should have a folder labeled <em>Android</em>.  (If you don’t see the
60<em>Android</em> folder,
61then you have not installed the ADT plugin&mdash;see <a
62href="{@docRoot}tools/sdk/eclipse-adt.html#installing">Installing the ADT Plugin</a>).</li>
63  <li>Open the <em>Android</em> folder, select <em>Android Project</em> and click
64<strong>Next</strong>.</li>
65  <li>Enter a project name (such as "MyFirstApp") and click <strong>Next</strong>.</li>
66  <li>Select a build target. This is the platform version against which you will compile your app.
67<p>We recommend that you select the latest version possible. You can still build your app to
68support older versions, but setting the build target to the latest version allows you to
69easily optimize your app for a great user experience on the latest Android-powered devices.</p>
70<p>If you don't see any built targets listed, you need to install some using the Android SDK
71Manager tool. See <a href="{@docRoot}sdk/installing/index.html#AddingComponents">step 4 in the
72installing guide</a>.</p>
73<p>Click <strong>Next</strong>.</p></li>
74  <li>Specify other app details, such as the:
75    <ul>
76      <li><em>Application Name</em>: The app name that appears to the user. Enter "My First
77App".</li>
78      <li><em>Package Name</em>: The package namespace for your app (following the same
79rules as packages in the Java programming language). Your package name
80must be unique across all packages installed on the Android system. For this reason, it's important
81that you use a standard domain-style package name that’s appropriate to your company or
82publisher entity. For
83your first app, you can use something like "com.example.myapp." However, you cannot publish your
84app using the "com.example" namespace.</li>
85      <li><em>Create Activity</em>: This is the class name for the primary user activity in your
86app (an activity represents a single screen in your app). Enter "MyFirstActivity".</li>
87      <li><em>Minimum SDK</em>: Select <em>4 (Android 1.6)</em>.
88        <p>Because this version is lower than the build target selected for the app, a warning
89appears, but that's alright. You simply need to be sure that you don't use any APIs that require an
90<a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">API level</a> greater than the minimum SDK
91version without first using some code to verify the device's system version (you'll see this in some
92other classes).</p>
93      </li>
94    </ul>
95    <p>Click <strong>Finish</strong>.</p>
96  </li>
97</ol>
98
99<p>Your Android project is now set up with some default files and you’re ready to begin
100building the app. Continue to the <a href="running-app.html">next lesson</a>.</p>
101
102
103
104<h2 id="CommandLine">Create a Project with Command Line Tools</h2>
105
106<p>If you're not using the Eclipse IDE with the ADT plugin, you can instead create your project
107using the SDK tools in a command line:</p>
108
109<ol>
110  <li>Change directories into the Android SDK’s <code>tools/</code> path.</li>
111  <li>Execute:
112<pre class="no-pretty-print">android list targets</pre>
113<p>This prints a list of the available Android platforms that you’ve downloaded for your SDK. Find
114the platform against which you want to compile your app. Make a note of the target id. We
115recommend that you select the highest version possible. You can still build your app to
116support older versions, but setting the build target to the latest version allows you to optimize
117your app for the latest devices.</p>
118<p>If you don't see any targets listed, you need to
119install some using the Android SDK
120Manager tool. See <a href="{@docRoot}sdk/installing/index.html#AddingComponents">step 4 in the
121installing guide</a>.</p></li>
122  <li>Execute:
123<pre class="no-pretty-print">
124android create project --target &lt;target-id> --name MyFirstApp \
125--path &lt;path-to-workspace>/MyFirstApp --activity MyFirstActivity \
126--package com.example.myapp
127</pre>
128<p>Replace <code>&lt;target-id></code> with an id from the list of targets (from the previous step)
129and replace
130<code>&lt;path-to-workspace></code> with the location in which you want to save your Android
131projects.</p></li>
132</ol>
133
134<p>Your Android project is now set up with several default configurations and you’re ready to begin
135building the app. Continue to the <a href="running-app.html">next lesson</a>.</p>
136
137<p class="note"><strong>Tip:</strong> Add the <code>platform-tools/</code> as well as the
138<code>tools/</code> directory to your <code>PATH</code> environment variable.</p>
139
140
141
142
143