|
| 1 | +page.title=Creating an Android Project |
| 2 | +parent.title=Building Your First App |
| 3 | +parent.link=index.html |
| 4 | + |
| 5 | +trainingnavtop=true |
| 6 | +next.title=Running Your App |
| 7 | +next.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.html">Installing the |
| 27 | +SDK</a></li> |
| 28 | + <li><a href="{@docRoot}guide/developing/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 |
| 36 | +app. The Android SDK tools make it easy to start a new Android project with a set of |
| 37 | +default project directories and files.</p> |
| 38 | + |
| 39 | +<p>This lesson |
| 40 | +shows how to create a new project either using Eclipse (with the ADT plugin) or using the |
| 41 | +SDK tools from a command line.</p> |
| 42 | + |
| 43 | +<p class="note"><strong>Note:</strong> You should already have the Android SDK installed, and if |
| 44 | +you're using Eclipse, you should have installed the <a |
| 45 | +href="{@docRoot}sdk/eclipse-adt.html">ADT plugin</a> as well. If you have not installed |
| 46 | +these, see <a href="{@docRoot}sdk/installing.html">Installing the Android SDK</a> and return here |
| 47 | +when 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 > New > Project</strong>. |
| 59 | +The resulting dialog should have a folder labeled <em>Android</em>. (If you don’t see the |
| 60 | +<em>Android</em> folder, |
| 61 | +then you have not installed the ADT plugin—see <a |
| 62 | +href="{@docRoot}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 |
| 68 | +support older versions, but setting the build target to the latest version allows you to |
| 69 | +easily 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 |
| 71 | +Manager tool. See <a href="{@docRoot}sdk/installing.html#AddingComponents">step 4 in the |
| 72 | +installing 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 |
| 77 | +App".</li> |
| 78 | + <li><em>Package Name</em>: The package namespace for your app (following the same |
| 79 | +rules as packages in the Java programming language). Your package name |
| 80 | +must be unique across all packages installed on the Android system. For this reason, it's important |
| 81 | +that you use a standard domain-style package name that’s appropriate to your company or |
| 82 | +publisher entity. For |
| 83 | +your first app, you can use something like "com.example.myapp." However, you cannot publish your |
| 84 | +app using the "com.example" namespace.</li> |
| 85 | + <li><em>Create Activity</em>: This is the class name for the primary user activity in your |
| 86 | +app (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 |
| 89 | +appears, 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/appendix/api-levels.html">API level</a> greater than the minimum SDK |
| 91 | +version without first using some code to verify the device's system version (you'll see this in some |
| 92 | +other 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 |
| 100 | +building 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 |
| 107 | +using 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 |
| 114 | +the platform against which you want to compile your app. Make a note of the target id. We |
| 115 | +recommend that you select the highest version possible. You can still build your app to |
| 116 | +support older versions, but setting the build target to the latest version allows you to optimize |
| 117 | +your app for the latest devices.</p> |
| 118 | +<p>If you don't see any targets listed, you need to |
| 119 | +install some using the Android SDK |
| 120 | +Manager tool. See <a href="{@docRoot}sdk/installing.html#AddingComponents">step 4 in the |
| 121 | +installing guide</a>.</p></li> |
| 122 | + <li>Execute: |
| 123 | +<pre class="no-pretty-print"> |
| 124 | +android create project --target <target-id> --name MyFirstApp \ |
| 125 | +--path <path-to-workspace>/MyFirstApp --activity MyFirstActivity \ |
| 126 | +--package com.example.myapp |
| 127 | +</pre> |
| 128 | +<p>Replace <code><target-id></code> with an id from the list of targets (from the previous step) |
| 129 | +and replace |
| 130 | +<code><path-to-workspace></code> with the location in which you want to save your Android |
| 131 | +projects.</p></li> |
| 132 | +</ol> |
| 133 | + |
| 134 | +<p>Your Android project is now set up with several default configurations and you’re ready to begin |
| 135 | +building 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 | + |
0 commit comments