Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 1 | page.title=Creating an Android Project |
smain@google.com | 61139c8 | 2014-10-20 14:29:22 -0700 | [diff] [blame] | 2 | |
smain@google.com | 0da6b00 | 2014-10-31 10:45:23 -0700 | [diff] [blame] | 3 | page.tags=project setup |
smain@google.com | 61139c8 | 2014-10-20 14:29:22 -0700 | [diff] [blame] | 4 | helpoutsWidget=true |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 5 | |
| 6 | trainingnavtop=true |
| 7 | next.title=Running Your App |
| 8 | next.link=running-app.html |
| 9 | |
| 10 | @jd:body |
| 11 | |
| 12 | |
| 13 | <!-- This is the training bar --> |
Ricardo Cervera | 8e5775d | 2014-04-01 10:46:16 -0700 | [diff] [blame] | 14 | <div id="tb-wrapper"> |
| 15 | <div id="tb"> |
| 16 | |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 17 | <h2>You should also read</h2> |
| 18 | |
| 19 | <ul> |
Mark Lu | 08d1bff | 2016-07-15 13:36:55 -0700 | [diff] [blame] | 20 | <li><a href="{@docRoot}studio/projects/index.html">Projects Overview</a></li> |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 21 | </ul> |
Ricardo Cervera | 8e5775d | 2014-04-01 10:46:16 -0700 | [diff] [blame] | 22 | |
| 23 | |
| 24 | </div> |
| 25 | </div> |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 26 | |
Mark Lu | 08d1bff | 2016-07-15 13:36:55 -0700 | [diff] [blame] | 27 | <p>This lesson shows you how to create a new Android project with |
| 28 | <a href="{@docRoot}studio/index.html">Android Studio</a> and describes some |
| 29 | of the files in the project.</p> |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 30 | |
Scott Main | 39871b7 | 2012-07-19 21:11:49 -0700 | [diff] [blame] | 31 | <ol> |
Scott Rowe | 8c068ae | 2014-05-19 16:50:47 -0700 | [diff] [blame] | 32 | <li>In Android Studio, create a new project: |
| 33 | <ul> |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 34 | <li>If you don't have a project opened, in the <strong>Welcome to Android Studio</strong> window, click <strong> |
| 35 | Start a new Android Studio project</strong>.</li> |
| 36 | <li>If you have a project opened, select <strong>File > New Project</strong>.</li> |
Scott Rowe | 8c068ae | 2014-05-19 16:50:47 -0700 | [diff] [blame] | 37 | </ul> |
| 38 | </li> |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 39 | <li>In the <b>New Project</b> screen, enter the following values:</p> |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 40 | <ul> |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 41 | <li><strong>Application Name</strong>: "My First App" </li> |
| 42 | <li><strong>Company Domain</strong>: "example.com"</li> |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 43 | </ul> |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 44 | <p>Android Studio fills in the package name and project location for you, |
| 45 | but you can edit these if you'd like. |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 46 | </li> |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 47 | <li>Click <b>Next</b>.</li> |
| 48 | <li>In the <b>Target Android Devices</b> screen, keep the default values and |
| 49 | click <b>Next</b>. |
| 50 | <p>The <b>Minimum Required SDK</b> is the earliest version of Android that your app supports, |
| 51 | which is indicated by the <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels"> |
Scott Rowe | 8c068ae | 2014-05-19 16:50:47 -0700 | [diff] [blame] | 52 | API level</a>. To support as many devices as possible, you should set this to the lowest |
| 53 | version available that allows your app to provide its core feature set. If any feature of your |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 54 | app is possible only on newer versions of Android and it's not critical to the core |
| 55 | feature set, enable that feature only when running on the versions that support it (see |
| 56 | <a href="{@docRoot}training/basics/supporting-devices/platforms.html"> |
Mark Lu | 08d1bff | 2016-07-15 13:36:55 -0700 | [diff] [blame] | 57 | Supporting Different Platform Versions</a>).</p> |
| 58 | </li> |
| 59 | |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 60 | <li>In the <strong>Add an Activity to Mobile</strong> screen, select <strong>Empty |
Mark Lu | 08d1bff | 2016-07-15 13:36:55 -0700 | [diff] [blame] | 61 | Activity</strong> and click <strong>Next</strong>. |
| 62 | </li> |
| 63 | |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 64 | <li>In the <strong>Customize the Activity</strong> screen, keep the default values |
Mark Lu | 08d1bff | 2016-07-15 13:36:55 -0700 | [diff] [blame] | 65 | and click <strong>Finish</strong>. |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 66 | </ol> |
| 67 | |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 68 | <p>After some processing, Android Studio opens and displays a "Hello World" app |
| 69 | with default files. You will add functionality to some of |
| 70 | these files in the following lessons.</p> |
| 71 | |
| 72 | <p>Now take a moment to review the most important files. First, be sure that |
| 73 | the <b>Project</b> window is open (select <b>View > Tool Windows > Project</b>) |
| 74 | and the <b>Android</b> view is selected from the drop-down list at the top. |
| 75 | You can then see the following files:</p> |
Scott Main | 2d6faf9 | 2012-03-02 18:02:43 -0800 | [diff] [blame] | 76 | |
Scott Rowe | 8c068ae | 2014-05-19 16:50:47 -0700 | [diff] [blame] | 77 | <dl> |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 78 | <dt><b>app > java > com.example.myfirstapp > MainActivity.java</b></dt> |
Mark Lu | 08d1bff | 2016-07-15 13:36:55 -0700 | [diff] [blame] | 79 | <dd>This file appears in Android Studio after the New Project wizard finishes. |
| 80 | It contains the class definition for the activity you created earlier. When you build |
| 81 | and run the app, the {@link android.app.Activity} starts and loads the |
| 82 | layout file that says "Hello World!"</dd> |
David Friedman | 7c6b7f7 | 2015-12-08 15:13:30 -0800 | [diff] [blame] | 83 | |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 84 | <dt><b>app > res > layout > activity_main.xml</b></dt> |
Mark Lu | 08d1bff | 2016-07-15 13:36:55 -0700 | [diff] [blame] | 85 | <dd>This XML file defines the layout of the activity. It contains a {@code TextView} |
| 86 | element with the text "Hello world!".</dd> |
David Friedman | 7c6b7f7 | 2015-12-08 15:13:30 -0800 | [diff] [blame] | 87 | |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 88 | <dt><b>app > manifests > AndroidManifest.xml</b></dt> |
Scott Rowe | 8c068ae | 2014-05-19 16:50:47 -0700 | [diff] [blame] | 89 | <dd>The <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">manifest file</a> describes |
| 90 | the fundamental characteristics of the app and defines each of its components. You'll revisit |
| 91 | this file as you follow these lessons and add more components to your app.</dd> |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 92 | |
| 93 | <dt><b>Gradle Scripts > build.gradle</b></dt> |
Scott Rowe | 8c068ae | 2014-05-19 16:50:47 -0700 | [diff] [blame] | 94 | <dd>Android Studio uses Gradle to compile and build your app. There is a <code>build.gradle</code> |
| 95 | file for each module of your project, as well as a <code>build.gradle</code> file for the entire |
smain@google.com | 14f51a7 | 2016-09-06 12:32:18 -0700 | [diff] [blame] | 96 | project. Usually, you're only interested in the <code>build.gradle</code> file for the module. |
| 97 | in this case the <code>app</code> or application module. For more information about this file, |
| 98 | see <a href="{@docRoot}studio/build/index.html">Building Your Project with Gradle</a>.</dd> |
Scott Rowe | 8c068ae | 2014-05-19 16:50:47 -0700 | [diff] [blame] | 99 | </dl> |
| 100 | |
Hemal Patel | 8d25ddd | 2016-07-01 13:33:14 -0700 | [diff] [blame] | 101 | <p> |
| 102 | To run the app, continue to the <a href="running-app.html">next lesson</a>. |
| 103 | </p> |