Loading docs/html/training/basics/firstapp/creating-project.jd +16 −11 Original line number Diff line number Diff line Loading @@ -100,10 +100,13 @@ lesson.</p> Activities</a> for more information.</p> </div> </div> <li>Under <strong>Add an activity to your project</strong>, select <strong>Blank Activity</strong> and click <strong>Next</strong>.</li> <li>Under <strong>Describe the new activity for your project</strong>, leave the fields as they are and click <strong>Finish</strong>.</li> <li>Under <strong>Add an activity to <<em>template</em>></strong>, select <strong>Blank Activity</strong> and click <strong>Next</strong>.</li> <li>Under <strong>Choose options for your new file</strong>, change the <strong>Activity Name</strong> to <em>MyActivity</em>. The <strong>Layout Name</strong> changes to <em>activity_my</em>, and the <strong>Title</strong> to <em>MyActivity</em>. The <strong>Menu Resource Name</strong> is <em>menu_my</em>. <li>Click the <strong>Finish</strong> button to create the project.</li> </ol> <p>Your Android project is now a basic "Hello World" app that contains some default files. Take a Loading @@ -120,7 +123,7 @@ moment to review the most important of these:</p> select the file you see the class definition for the activity you created. When you build and run the app, the {@link android.app.Activity} class starts the activity and loads the layout file that says "Hello World!"</dd> <dt><code>app/src/res/AndroidManifest.xml</code></dt> <dt><code>app/src/main/AndroidManifest.xml</code></dt> <dd>The <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">manifest file</a> describes the fundamental characteristics of the app and defines each of its components. You'll revisit this file as you follow these lessons and add more components to your app.</dd> Loading Loading @@ -156,13 +159,16 @@ moment to review the most important of these:</p> <p>Note also the <code>/res</code> subdirectories that contain the <a href="{@docRoot}guide/topics/resources/overview.html">resources</a> for your application:</p> <dl> <dt><code>drawable-hdpi/</code></dt> <dd>Directory for drawable objects (such as bitmaps) that are designed for high-density (hdpi) screens. Other drawable directories contain assets designed for other screen densities. <dt><code>drawable<em><density></em>/</code></dt> <dd>Directories for drawable objects (such as bitmaps) that are designed for various densities, such as medium-density (mdpi) and high-density (hdpi) screens. Other drawable directories contain assets designed for other screen densities. Here you'll find the ic_launcher.png that appears when you run the default app.</dd> <dt><code>layout/</code></dt> <dd>Directory for files that define your app's user interface like activity_my.xml, discussed above, which describes a basic layout for the MyActivity class.</dd> <dt><code>menu/</code></dt> <dd>Directory for files that define your app's menu items.</dd> <dt><code>values/</code></dt> <dd>Directory for other XML files that contain a collection of resources, such as string and color definitions. The strings.xml file defines the "Hello world!" string that Loading @@ -177,9 +183,9 @@ moment to review the most important of these:</p> using the SDK tools from a command line:</p> <ol> <li>Change directories into the Android SDK’s <code>tools/</code> path.</li> <li>Change directories into the Android SDK’s <code>sdk/</code> path.</li> <li>Execute: <pre class="no-pretty-print">android list targets</pre> <pre class="no-pretty-print">tools/android list targets</pre> <p>This prints a list of the available Android platforms that you’ve downloaded for your SDK. Find the platform against which you want to compile your app. Make a note of the target ID. We recommend that you select the highest version possible. You can still build your app to Loading Loading @@ -209,4 +215,3 @@ To run the app, continue to the <a href="running-app.html">next lesson</a>.</p> docs/html/training/basics/firstapp/running-app.jd +48 −33 Original line number Diff line number Diff line Loading @@ -83,14 +83,37 @@ from the toolbar.</li> <h3>Run the app from a command line</h3> <ol> <li>Change directories to the root of your Android project and execute: <pre class="no-pretty-print">ant debug</pre></li> <li>Make sure the Android SDK <code>platform-tools/</code> directory is included in your <p>Open a command-line and navigate to the root of your project directory. Use Gradle to build your project in debug mode, invoke the <code>assembleDebug</code> build task using the Gradle wrapper script (<code>gradlew assembleRelease</code>). <p>This creates your debug <code>.apk</code> file inside the module <code>build/</code> directory, named <code>MyFirstApp-debug.apk</code>. </p> <p>On Windows platforms, type this command:</p> <pre> > gradlew.bat assembleDebug </pre> <p>On Mac OS and Linux platforms, type these commands:</p> <pre> $ chmod +x gradlew $ ./gradlew assembleDebug </pre> <p>After you build the project, the output APK for the app module is located in <code>app/build/outputs/apk/</code> <p class="note"><strong>Note:</strong> The first command (<code>chmod</code>) adds the execution permission to the Gradle wrapper script and is only necessary the first time you build this project from the command line.</p> <p>Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable, then execute: <pre class="no-pretty-print">adb install bin/MyFirstApp-debug.apk</pre></li> <li>On your device, locate <em>MyFirstApp</em> and open it.</li> </ol> <pre class="no-pretty-print">adb install app/build/outputs/MyFirstApp-debug.apk</pre><p> <p>On your device, locate <em>MyFirstApp</em> and open it.</p> <p>That's how you build and run your Android app on a device! To start developing, continue to the <a href="building-ui.html">next Loading @@ -113,11 +136,11 @@ device.</p> <li>In Android Studio, select <strong>Tools > Android > AVD Manager</strong>, or click the AVD Manager icon <img src="{@docRoot}images/tools/avd-manager-studio.png" style="vertical-align:bottom;margin:0;height:19px"> in the toolbar.</li> <li>Or, from the command line, change directories to <code><sdk>/tools/</code> and execute: <pre class="no-pretty-print">android avd</pre> <code>sdk/</code> and execute: <pre class="no-pretty-print">tools/android avd</pre> <p class="note"><strong>Note:</strong> The AVD Manager that appears when launched from the command line is different from the version in Android Studio, so the following instructions may not apply.</p> Android Studio, so the following instructions may not all apply.</p> </li> </ul> Loading @@ -127,7 +150,6 @@ device.</p> </li> <li>On the AVD Manager main screen (figure 1), click <strong>Create Virtual Device</strong>.</li> <li>In the Select Hardware window, select a device configuration, such as Nexus 6, then click <strong>Next</strong>. </li> Loading @@ -143,25 +165,27 @@ device.</p> <h3>Run the app from Android Studio</h3> <ol> <li>In <strong>Android Studio</strong>, select your project and click <strong>Run</strong> <img src="{@docRoot}images/tools/as-run.png" style="vertical-align:baseline;margin:0; max-height:1em" /> from the toolbar.</li> <img src="{@docRoot}images/tools/as-run.png" style="vertical-align:baseline;margin:0; max-height:1em" /> from the toolbar.</li> <li>In the <strong>Choose Device</strong> window, click the <strong>Launch emulator</strong> radio button.</li> <li>From the <strong>Android virtual device</strong> pull-down menu, select the emulator you created, and click <strong>OK</strong>.</li> </ol> <p>It can take a few minutes for the emulator to load itself. You may have to unlock the screen. When you do, My First App appears on the emulator screen.</p> When you do, <em>My First App</em> appears on the emulator screen.</p> <h3>Run your app from the command line</h3> <ol> <li>Change directories to the root of your Android project and execute: <pre class="no-pretty-print">ant debug</pre></li> <li>Build the project from the command line. The output APK for the app module is located in <code>app/build/outputs/apk/</code>.</li> <li>Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable, then execute: <pre class="no-pretty-print">adb install bin/MyFirstApp-debug.apk</pre></li> <code>PATH</code> environment variable.</li> <li>Execute this command: <p> <pre class="no-pretty-print">adb install app/build/outputs/MyFirstApp-debug.apk</pre> </p> </li> <li>On the emulator, locate <em>MyFirstApp</em> and open it.</li> </ol> Loading @@ -171,12 +195,3 @@ device.</p> lesson</a>.</p> Loading
docs/html/training/basics/firstapp/creating-project.jd +16 −11 Original line number Diff line number Diff line Loading @@ -100,10 +100,13 @@ lesson.</p> Activities</a> for more information.</p> </div> </div> <li>Under <strong>Add an activity to your project</strong>, select <strong>Blank Activity</strong> and click <strong>Next</strong>.</li> <li>Under <strong>Describe the new activity for your project</strong>, leave the fields as they are and click <strong>Finish</strong>.</li> <li>Under <strong>Add an activity to <<em>template</em>></strong>, select <strong>Blank Activity</strong> and click <strong>Next</strong>.</li> <li>Under <strong>Choose options for your new file</strong>, change the <strong>Activity Name</strong> to <em>MyActivity</em>. The <strong>Layout Name</strong> changes to <em>activity_my</em>, and the <strong>Title</strong> to <em>MyActivity</em>. The <strong>Menu Resource Name</strong> is <em>menu_my</em>. <li>Click the <strong>Finish</strong> button to create the project.</li> </ol> <p>Your Android project is now a basic "Hello World" app that contains some default files. Take a Loading @@ -120,7 +123,7 @@ moment to review the most important of these:</p> select the file you see the class definition for the activity you created. When you build and run the app, the {@link android.app.Activity} class starts the activity and loads the layout file that says "Hello World!"</dd> <dt><code>app/src/res/AndroidManifest.xml</code></dt> <dt><code>app/src/main/AndroidManifest.xml</code></dt> <dd>The <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">manifest file</a> describes the fundamental characteristics of the app and defines each of its components. You'll revisit this file as you follow these lessons and add more components to your app.</dd> Loading Loading @@ -156,13 +159,16 @@ moment to review the most important of these:</p> <p>Note also the <code>/res</code> subdirectories that contain the <a href="{@docRoot}guide/topics/resources/overview.html">resources</a> for your application:</p> <dl> <dt><code>drawable-hdpi/</code></dt> <dd>Directory for drawable objects (such as bitmaps) that are designed for high-density (hdpi) screens. Other drawable directories contain assets designed for other screen densities. <dt><code>drawable<em><density></em>/</code></dt> <dd>Directories for drawable objects (such as bitmaps) that are designed for various densities, such as medium-density (mdpi) and high-density (hdpi) screens. Other drawable directories contain assets designed for other screen densities. Here you'll find the ic_launcher.png that appears when you run the default app.</dd> <dt><code>layout/</code></dt> <dd>Directory for files that define your app's user interface like activity_my.xml, discussed above, which describes a basic layout for the MyActivity class.</dd> <dt><code>menu/</code></dt> <dd>Directory for files that define your app's menu items.</dd> <dt><code>values/</code></dt> <dd>Directory for other XML files that contain a collection of resources, such as string and color definitions. The strings.xml file defines the "Hello world!" string that Loading @@ -177,9 +183,9 @@ moment to review the most important of these:</p> using the SDK tools from a command line:</p> <ol> <li>Change directories into the Android SDK’s <code>tools/</code> path.</li> <li>Change directories into the Android SDK’s <code>sdk/</code> path.</li> <li>Execute: <pre class="no-pretty-print">android list targets</pre> <pre class="no-pretty-print">tools/android list targets</pre> <p>This prints a list of the available Android platforms that you’ve downloaded for your SDK. Find the platform against which you want to compile your app. Make a note of the target ID. We recommend that you select the highest version possible. You can still build your app to Loading Loading @@ -209,4 +215,3 @@ To run the app, continue to the <a href="running-app.html">next lesson</a>.</p>
docs/html/training/basics/firstapp/running-app.jd +48 −33 Original line number Diff line number Diff line Loading @@ -83,14 +83,37 @@ from the toolbar.</li> <h3>Run the app from a command line</h3> <ol> <li>Change directories to the root of your Android project and execute: <pre class="no-pretty-print">ant debug</pre></li> <li>Make sure the Android SDK <code>platform-tools/</code> directory is included in your <p>Open a command-line and navigate to the root of your project directory. Use Gradle to build your project in debug mode, invoke the <code>assembleDebug</code> build task using the Gradle wrapper script (<code>gradlew assembleRelease</code>). <p>This creates your debug <code>.apk</code> file inside the module <code>build/</code> directory, named <code>MyFirstApp-debug.apk</code>. </p> <p>On Windows platforms, type this command:</p> <pre> > gradlew.bat assembleDebug </pre> <p>On Mac OS and Linux platforms, type these commands:</p> <pre> $ chmod +x gradlew $ ./gradlew assembleDebug </pre> <p>After you build the project, the output APK for the app module is located in <code>app/build/outputs/apk/</code> <p class="note"><strong>Note:</strong> The first command (<code>chmod</code>) adds the execution permission to the Gradle wrapper script and is only necessary the first time you build this project from the command line.</p> <p>Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable, then execute: <pre class="no-pretty-print">adb install bin/MyFirstApp-debug.apk</pre></li> <li>On your device, locate <em>MyFirstApp</em> and open it.</li> </ol> <pre class="no-pretty-print">adb install app/build/outputs/MyFirstApp-debug.apk</pre><p> <p>On your device, locate <em>MyFirstApp</em> and open it.</p> <p>That's how you build and run your Android app on a device! To start developing, continue to the <a href="building-ui.html">next Loading @@ -113,11 +136,11 @@ device.</p> <li>In Android Studio, select <strong>Tools > Android > AVD Manager</strong>, or click the AVD Manager icon <img src="{@docRoot}images/tools/avd-manager-studio.png" style="vertical-align:bottom;margin:0;height:19px"> in the toolbar.</li> <li>Or, from the command line, change directories to <code><sdk>/tools/</code> and execute: <pre class="no-pretty-print">android avd</pre> <code>sdk/</code> and execute: <pre class="no-pretty-print">tools/android avd</pre> <p class="note"><strong>Note:</strong> The AVD Manager that appears when launched from the command line is different from the version in Android Studio, so the following instructions may not apply.</p> Android Studio, so the following instructions may not all apply.</p> </li> </ul> Loading @@ -127,7 +150,6 @@ device.</p> </li> <li>On the AVD Manager main screen (figure 1), click <strong>Create Virtual Device</strong>.</li> <li>In the Select Hardware window, select a device configuration, such as Nexus 6, then click <strong>Next</strong>. </li> Loading @@ -143,25 +165,27 @@ device.</p> <h3>Run the app from Android Studio</h3> <ol> <li>In <strong>Android Studio</strong>, select your project and click <strong>Run</strong> <img src="{@docRoot}images/tools/as-run.png" style="vertical-align:baseline;margin:0; max-height:1em" /> from the toolbar.</li> <img src="{@docRoot}images/tools/as-run.png" style="vertical-align:baseline;margin:0; max-height:1em" /> from the toolbar.</li> <li>In the <strong>Choose Device</strong> window, click the <strong>Launch emulator</strong> radio button.</li> <li>From the <strong>Android virtual device</strong> pull-down menu, select the emulator you created, and click <strong>OK</strong>.</li> </ol> <p>It can take a few minutes for the emulator to load itself. You may have to unlock the screen. When you do, My First App appears on the emulator screen.</p> When you do, <em>My First App</em> appears on the emulator screen.</p> <h3>Run your app from the command line</h3> <ol> <li>Change directories to the root of your Android project and execute: <pre class="no-pretty-print">ant debug</pre></li> <li>Build the project from the command line. The output APK for the app module is located in <code>app/build/outputs/apk/</code>.</li> <li>Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable, then execute: <pre class="no-pretty-print">adb install bin/MyFirstApp-debug.apk</pre></li> <code>PATH</code> environment variable.</li> <li>Execute this command: <p> <pre class="no-pretty-print">adb install app/build/outputs/MyFirstApp-debug.apk</pre> </p> </li> <li>On the emulator, locate <em>MyFirstApp</em> and open it.</li> </ol> Loading @@ -171,12 +195,3 @@ device.</p> lesson</a>.</p>