blob: 60be5f6a3ab42d2b1cc3b0ef1b0f8cd97030b538 [file] [log] [blame]
Scott Main2d6faf92012-03-02 18:02:43 -08001page.title=Creating an Android Project
smain@google.com61139c82014-10-20 14:29:22 -07002
smain@google.com0da6b002014-10-31 10:45:23 -07003page.tags=project setup
smain@google.com61139c82014-10-20 14:29:22 -07004helpoutsWidget=true
Scott Main2d6faf92012-03-02 18:02:43 -08005
6trainingnavtop=true
7next.title=Running Your App
8next.link=running-app.html
9
10@jd:body
11
12
13<!-- This is the training bar -->
Ricardo Cervera8e5775d2014-04-01 10:46:16 -070014<div id="tb-wrapper">
15<div id="tb">
16
Scott Main2d6faf92012-03-02 18:02:43 -080017<h2>You should also read</h2>
18
19<ul>
Mark Lu08d1bff2016-07-15 13:36:55 -070020 <li><a href="{@docRoot}studio/projects/index.html">Projects Overview</a></li>
Scott Main2d6faf92012-03-02 18:02:43 -080021</ul>
Ricardo Cervera8e5775d2014-04-01 10:46:16 -070022
23
24</div>
25</div>
Scott Main2d6faf92012-03-02 18:02:43 -080026
Mark Lu08d1bff2016-07-15 13:36:55 -070027<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 Main2d6faf92012-03-02 18:02:43 -080030
Scott Main39871b72012-07-19 21:11:49 -070031<ol>
Scott Rowe8c068ae2014-05-19 16:50:47 -070032 <li>In Android Studio, create a new project:
33 <ul>
smain@google.com14f51a72016-09-06 12:32:18 -070034 <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 Rowe8c068ae2014-05-19 16:50:47 -070037 </ul>
38 </li>
smain@google.com14f51a72016-09-06 12:32:18 -070039 <li>In the <b>New Project</b> screen, enter the following values:</p>
Scott Main2d6faf92012-03-02 18:02:43 -080040 <ul>
smain@google.com14f51a72016-09-06 12:32:18 -070041 <li><strong>Application Name</strong>: "My First App" </li>
42 <li><strong>Company Domain</strong>: "example.com"</li>
Scott Main2d6faf92012-03-02 18:02:43 -080043 </ul>
smain@google.com14f51a72016-09-06 12:32:18 -070044 <p>Android Studio fills in the package name and project location for you,
45 but you can edit these if you'd like.
Scott Main2d6faf92012-03-02 18:02:43 -080046 </li>
smain@google.com14f51a72016-09-06 12:32:18 -070047 <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 Rowe8c068ae2014-05-19 16:50:47 -070052 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.com14f51a72016-09-06 12:32:18 -070054 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 Lu08d1bff2016-07-15 13:36:55 -070057 Supporting Different Platform Versions</a>).</p>
58 </li>
59
smain@google.com14f51a72016-09-06 12:32:18 -070060 <li>In the <strong>Add an Activity to Mobile</strong> screen, select <strong>Empty
Mark Lu08d1bff2016-07-15 13:36:55 -070061 Activity</strong> and click <strong>Next</strong>.
62 </li>
63
smain@google.com14f51a72016-09-06 12:32:18 -070064 <li>In the <strong>Customize the Activity</strong> screen, keep the default values
Mark Lu08d1bff2016-07-15 13:36:55 -070065 and click <strong>Finish</strong>.
Scott Main2d6faf92012-03-02 18:02:43 -080066</ol>
67
smain@google.com14f51a72016-09-06 12:32:18 -070068<p>After some processing, Android Studio opens and displays a "Hello World" app
69with default files. You will add functionality to some of
70these files in the following lessons.</p>
71
72<p>Now take a moment to review the most important files. First, be sure that
73the <b>Project</b> window is open (select <b>View > Tool Windows > Project</b>)
74and the <b>Android</b> view is selected from the drop-down list at the top.
75You can then see the following files:</p>
Scott Main2d6faf92012-03-02 18:02:43 -080076
Scott Rowe8c068ae2014-05-19 16:50:47 -070077<dl>
smain@google.com14f51a72016-09-06 12:32:18 -070078 <dt><b>app > java > com.example.myfirstapp > MainActivity.java</b></dt>
Mark Lu08d1bff2016-07-15 13:36:55 -070079 <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 Friedman7c6b7f72015-12-08 15:13:30 -080083
smain@google.com14f51a72016-09-06 12:32:18 -070084 <dt><b>app > res > layout > activity_main.xml</b></dt>
Mark Lu08d1bff2016-07-15 13:36:55 -070085 <dd>This XML file defines the layout of the activity. It contains a {@code TextView}
86 element with the text "Hello world!".</dd>
David Friedman7c6b7f72015-12-08 15:13:30 -080087
smain@google.com14f51a72016-09-06 12:32:18 -070088 <dt><b>app > manifests > AndroidManifest.xml</b></dt>
Scott Rowe8c068ae2014-05-19 16:50:47 -070089 <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.com14f51a72016-09-06 12:32:18 -070092
93 <dt><b>Gradle Scripts > build.gradle</b></dt>
Scott Rowe8c068ae2014-05-19 16:50:47 -070094 <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.com14f51a72016-09-06 12:32:18 -070096 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 Rowe8c068ae2014-05-19 16:50:47 -070099</dl>
100
Hemal Patel8d25ddd2016-07-01 13:33:14 -0700101<p>
102 To run the app, continue to the <a href="running-app.html">next lesson</a>.
103</p>