Bearbeiten von „Android Training/Running Your Application

    Du bearbeitest die Quelle einer übersetzbaren Seite. Bitte stelle sicher, dass du mit der folgenden Dokumentation vertraut bist:

    Warnung: Du bist nicht angemeldet. Deine IP-Adresse wird bei Bearbeitungen öffentlich sichtbar. Melde dich an oder erstelle ein Benutzerkonto, damit Bearbeitungen deinem Benutzernamen zugeordnet werden. Ein eigenes Benutzerkonto hat eine ganze Reihe von Vorteilen.

    Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.

    Aktuelle Version Dein Text
    Zeile 1: Zeile 1:
    <languages />
    If you followed the [[Android Training/ Ein Android-Projekt erstellen|previous lesson]] to create an Android project, it includes a default set of "Hello World" source files that allow you to run the app right away.
    <translate>
    <!--T:1-->
    If you followed the [[Spezial:MyLanguage/Android Training/Creating an Android Project|previous lesson]] to create an Android project, it includes a default set of "Hello World" source files that allow you to immediately run the app.


    <!--T:2-->
    How you run your app depends on two things: whether you have a real Android-powered device and whether you’re using Eclipse. This lesson shows you how to install and run your app on a real device and on the Android emulator, and in both cases with either Eclipse or the command line tools.
    How you run your app depends on two things: whether you have a real device running Android and whether you're using Android Studio. This lesson shows you how to install and run your app on a real device and on the Android emulator, and in both cases with either Android Studio or the command line tools.


    == Run on a Real Device == <!--T:3-->
    Before you run your app, you should be aware of a few directories and files in the Android project:


    <!--T:4-->
    ; <code>AndroidManifest.xml</code> : This manifest file describes the fundamental characteristics of the app and defines each of its components. You'll learn about various declarations in this file as you read more training classes.
    If you have a device running Android, here's how to install and run your app.
    ; <code>src/</code> : Directory for your app's main source files. By default, it includes an <code>[http://developer.android.com/reference/android/app/Activity.html Activity]</code> class that runs when your app is launched using the app icon.
    ; <code>res/</code> : Contains several sub-directories for app resources. Here are just a few:
    :; <code>drawable-hdpi/</code> : 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.
    :; <code>layout/</code> : Directory for files that define your app's user interface.
    :; <code>values/</code> : Directory for other various XML files that contain a collection of resources, such as string and color definitions.


    === Set up your device === <!--T:5-->
    When you build and run the default Android project, the default <code>[http://developer.android.com/reference/android/app/Activity.html Activity]</code> class in the <code>src/</code> directory starts and loads a layout file from the <code>layout/</code> directory, which includes a "Hello World" message. Not real exciting, but it's important that you understand how to build and run your app before adding real functionality to the app.
    # Plug in your device to your development machine with a USB cable. If you're developing on Windows, you might need to install the appropriate USB driver for your device. For help installing drivers, see the [http://developer.android.com/tools/extras/oem-usb.html OEM USB Drivers] document.
    # Enable '''USB debugging''' on your device.
    #* On most devices running Android 3.2 or older, you can find the option under '''Settings > Applications > Development'''.
    #* On Android 4.0 and newer, it's in '''Settings > Developer options'''.
    #: '''Note:''' On Android 4.2 and newer, '''Developer options''' is hidden by default. To make it available, go to'''Settings > About phone''' and tap '''Build number''' seven times. Return to the previous screen to find '''Developer options'''.


    === Run the app from Android Studio === <!--T:6-->
    == Run on a Real Device ==
    # Select one of your project's files and click '''Run''' from the toolbar.
    # In the '''Choose Device''' window that appears, select the '''Choose a running device''' radio button, select your device, and click '''OK''' .
    Android Studio installs the app on your connected device and starts it.


    === Run the app from a command line === <!--T:7-->
    Whether you’re using Eclipse or the command line, you need to:
    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>).


    <!--T:8-->
    # Plug in your Android-powered device to your machine with a USB cable. If you’re developing on Windows, you might need to install the appropriate USB driver for your device. For help installing drivers, see the [http://developer.android.com/tools/extras/oem-usb.html OEM USB Drivers] document.
    This creates your debug <code>.apk</code> file inside the module <code>build/</code> directory, named <code>MyFirstApp-debug.apk</code>.
    # Ensure that '''USB debugging''' is enabled in the device Settings (open Settings and navitage to '''Applications > Development''' on most devices, or select '''Developer options''' on Android 4.0 and higher).


    <!--T:9-->
    To run the app from Eclipse, open one of your project's files and click '''Run''' from the toolbar. Eclipse installs the app on your connected device and starts it.
    On Windows platforms, type this command:</translate>
    > gradlew.bat assembleDebug
    <translate>
    <!--T:10-->
    On Mac OS and Linux platforms, type these commands:</translate>
    $ chmod +x gradlew
    $ ./gradlew assembleDebug
    <translate>
    <!--T:11-->
    After you build the project, the output APK for the app module is located in <code>app/build/outputs/apk/</code>


    <!--T:12-->
    Or to run your app from a command line:
    '''Note:''' 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.


    <!--T:13-->
    # Change directories to the root of your Android project and execute:<pre>ant debug</pre>
    Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable, then execute:</translate>
    # Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable, then execute:<pre>adb install bin/MyFirstApp-debug.apk</pre>
    adb install app/build/outputs/MyFirstApp-debug.apk
    # On your device, locate ''MyFirstActivity'' and open it.
    <translate>
    <!--T:14-->
    On your device, locate ''MyFirstApp'' and open it.


    <!--T:15-->
    To start adding stuff to the app, continue to the [[Android Training/ Eine einfache Benutzeroberfläche erstellen|next lesson]].
    That's how you build and run your Android app on a device! To start developing, continue to the [[Spezial:MyLanguage/Android Training/Building a Simple User Interface|next lesson]].


    == Run on the Emulator == <!--T:16-->
    == Run on the Emulator ==
    Whether you're using Android Studio or the command line, to run your app on the emulator you need to first create an [[Android Virtual Device](AVD). An AVD is a device configuration for the Android emulator that allows you to model a specific device.
    Whether you’re using Eclipse or the command line, you need to first create an [http://developer.android.com/tools/devices/index.html Android Virtual Device] (AVD). An AVD is a device configuration for the Android emulator that allows you to model different device configurations.
    [[Datei:Avds-config.png|thumb|'''Figure 1.''' The AVD Manager main screen shows your current virtual devices.]]
    [[Datei:Avds-config.png|thumb|The AVD Manager showing a few virtual devices.]]
    To create an AVD:


    === Create an AVD === <!--T:17-->
    # Launch the Android Virtual Device Manager:
    # Launch the Android Virtual Device Manager:
    #* In Android Studio, select '''Tools > Android > AVD Manager''', or click the AVD Manager icon in the toolbar.
    ## In Eclipse, select '''Window > AVD Manager''', or click the ''AVD Manager'' icon in the Eclipse toolbar.
    #* Or, from the command line, change directories to <code>sdk/</code> and execute:</translate>
    ## From the command line, change directories to <code><sdk>/tools/</code> and execute:<pre>./android avd</pre>
    #: <code>tools/android avd</code>
    # In the ''Android Virtual Device Device Manager'' panel, click '''New'''.
    #: <translate><!--T:18-->
    # Fill in the details for the AVD. Give it a name, a platform target, an SD card size, and a skin (HVGA is default).
    '''Note:''' 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 all apply.
    # Click '''Create AVD'''.
    # On the AVD Manager main screen (figure 1), click '''Create Virtual Device'''.
    # Select the new AVD from the ''Android Virtual Device Manager'' and click '''Start'''.
    # In the Select Hardware window, select a device configuration, such as Nexus 6, then click '''Next'''.
    # After the emulator boots up, unlock the emulator screen.
    # Select the desired system version for the AVD and click '''Next'''.
    # Verify the configuration settings, then click '''Finish'''.
    For more information about using AVDs, see [http://developer.android.com/tools/devices/managing-avds.html Managing AVDs with AVD Manager].


    === Run the app from Android Studio === <!--T:19-->
    To run the app from Eclipse, open one of your project's files and click '''Run''' from the toolbar. Eclipse installs the app on your AVD and starts it.
    # In '''Android Studio''', select your project and click '''Run''' from the toolbar.
    # In the '''Choose Device''' window, click the '''Launch emulator''' radio button.
    # From the '''Android virtual device''' pull-down menu, select the emulator you created, and click '''OK'''.
    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.


    === Run your app from the command line === <!--T:20-->
    Or to run your app from the command line:
    # Build the project from the command line. The output APK for the app module is located in<code>app/build/outputs/apk/</code>.
    # Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable.
    # Execute this command:</translate>
    #: <code>adb install app/build/outputs/MyFirstApp-debug.apk</code>
    # <translate><!--T:21-->
    On the emulator, locate ''MyFirstApp'' and open it.
    That's how you build and run your Android app on the emulator! To start developing, continue to the [[Spezial:MyLanguage/Android Training/Building a Simple User Interface|next lesson]].
    </translate>


    {{TNT|Android Training/Attribution}}
    # Change directories to the root of your Android project and execute:<pre>ant debug</pre>
    [[Kategorie:Android Training]]
    # Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable, then execute:<pre>adb install bin/MyFirstApp-debug.apk</pre>
    # On the emulator, locate ''MyFirstActivity'' and open it.
     
    To start adding stuff to the app, continue to the [[Android Training/ Eine einfache Benutzeroberfläche erstellen|next lesson]].
     
    {{Android Training/ Vorlage:Attribution}}
    Bitte kopiere keine Webseiten, die nicht deine eigenen sind, benutze keine urheberrechtlich geschützten Werke ohne Erlaubnis des Urhebers!
    Du gibst uns hiermit deine Zusage, dass du den Text selbst verfasst hast, dass der Text Allgemeingut (public domain) ist, oder dass der Urheber seine Zustimmung gegeben hat. Falls dieser Text bereits woanders veröffentlicht wurde, weise bitte auf der Diskussionsseite darauf hin. Bitte beachte, dass alle Android Wiki-Beiträge automatisch unter der „Creative Commons Attribution/Share-Alike Lizenz 3.0“ stehen. Falls du nicht möchtest, dass deine Arbeit hier von anderen verändert und verbreitet wird, dann klicke nicht auf „Seite speichern“.

    Um das Wiki vor automatisiertem Bearbeitungsspam zu schützen, bitten wir dich, das folgende CAPTCHA zu lösen:

    Abbrechen Bearbeitungshilfe (wird in einem neuen Fenster geöffnet)

    Folgende Vorlagen werden auf dieser Seite verwendet: