Android Training/Running Your Application: Unterschied zwischen den Versionen

Aus Android Wiki
K (Florian verschob die Seite Android Training/Deine App starten nach Android Training/Running Your Application: wird später auf deutsch übersetzt)
Keine Bearbeitungszusammenfassung
 
(8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
{{DISPLAYTITLE:Android Training: Deine App startenp}}
<languages />
Wenn Du der [[Android Training/ Ein Android-Projekt erstellen|vorherigen Lektion]] zur Erstellung eines Android-Projektes gefolgt bist, erhält es einige Standard-''Hello World''-Quellcode-Dateien die Dir erlauben deine [[App]] sofort zu starten.
<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.


Wie Du deine [[App]] ausführst hängt von zwei Dingen ab: ob Du ein echtes Android-Gerät hast und ob Du Eclipse benutzt. Diese Lektion zeigt Dir wie Du Deine [[App]] auf einem echten Gerät und im Android Emulator installierst und ausführst, in beiden Fällen jeweils mit Eclipse und Kommandozeilenwerkzeugen.
<!--T:2-->
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.


Bevor Du Deine [[App]] startest solltest Du ein paar Verzeichnisse und Dateien in dem Android-Projekt kennen:
== Run on a Real Device == <!--T:3-->
; <code>AndroidManifest.xml</code> : Diese Manifest-Datei beschreibt die grundlegenden Charakteristiken der [[App]] und definiert jede ihrer Komponenten. Du wirst verschiedene Deklarationen in dieser Datei lernen wenn du weitere Lektionen liest.
; <code>src/</code> : Verzeichnis für die Haupt-Quellcode-Dateien deiner [[App]]. Standardmäßig enthält es eine <code>[http://developer.android.com/reference/android/app/Activity.html Activity]</code>-Klasse welche ausgeführt wird wenn deine [[App]] über das [[App]]-Icon gestartet wird.
; <code>res/</code> : Enthält einige Unterverzeichnisse für [[App]]-Ressourcen. Hier sind ein paar:
:; <code>drawable-hdpi/</code> : Verzeichnis für Grafikobjekte (wie Bitmaps) die für Displays mit hoher Pixeldichte gestaltet wurden. Andere Grafikverzeichnisse enthalten Dateien die für andere Pixeldichten gestaltet sind.
:; <code>layout/</code> : Verzeichnis für Dateien welche die Benutzeroberfläche Deiner [[App]] beschreiben.


Wenn du das Standard-Android-Projekt erstellst und ausführst, wird die Standard-<code>[http://developer.android.com/reference/android/app/Activity.html Activity]</code>-Klasse im <code>src/</code>-Verzeichnis gestartet und lädt eine Layout-Datei aus dem <code>layout/</code>-Verzeichnis, welche eine "Hallo Welt"-Nachricht enthält. Nicht wirklich spannend, aber es ist wichtig das du verstehst wie du deine [[App]] erstellst und ausführst bevor du richtige Funktionen hinzufügst.
<!--T:4-->
If you have a device running Android, here's how to install and run your app.


== Auf einem echten Gerät starten ==
=== Set up your device === <!--T:5-->
# 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'''.


Unabhängig, ob du Eclipse oder die Kommandozeile verwendest, musst du vor dem Start:
=== Run the app from Android Studio === <!--T:6-->
# 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.


# Dein Android Gerät per USB mit dem Computer verbinden. Wenn du unter Windows entwickelst, musst du den entsprechenden USB-Treiber für das Gerät installieren. Hilfe zur Installieren der Treiber findest du hier: [http://developer.android.com/tools/extras/oem-usb.html OEM USB Drivers].
=== Run the app from a command line === <!--T:7-->
# Sicherstellen das USB-Debugging auf dem Gerät aktiviert ist. Gehe hierzu in die Einstellungen deines Gerätes und navigiere zu '''Einstellungen->Entwickler-Optinen''' und setze einen Hacken bei '''USB-Debugging'''.
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>).


Um die [[App]] aus Eclipse heraus auszuführen, musst du eine Datei deines Projektes öffnen und in der Symbolleiste auf '''Run ''' klicken. Eclipse installiert die [[App]] auf dem angeschlossenen Gerät und startet sie.
<!--T:8-->
This creates your debug <code>.apk</code> file inside the module <code>build/</code> directory, named <code>MyFirstApp-debug.apk</code>.


Wenn du statt Eclipse die Kommandozeile verwendest, führe folgende Schritte aus:
<!--T:9-->
# Wechsle in das Stammverzeichnis von deinem Android Projekt und führe <pre>ant debug</pre> aus
On Windows platforms, type this command:</translate>
# Stelle sicher dass das Android-SDK /plattform-tools-Verzeichnis in deinen PATH-Umgebungsvariablen enthalten ist, und führe <pre>adb install bin/MyFirstApp-debug.apk</pre> aus
> gradlew.bat assembleDebug
# Suche auf deinem Gerät nun die [[App]] ''MyFirstActivity'' und starte sie
<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>


Weiter geht es mit dem [[Android Training/ Eine einfache Benutzeroberfläche erstellen|Nächsten Schritt]].
<!--T:12-->
'''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.


== Im Emulator ausführen ==
<!--T:13-->
Unabhängig davon ob du Eclipse oder die Kommandozeile verwendest, musst du ein [http://developer.android.com/tools/devices/index.html Android Virtual Device] (AVD) erzeugen. Ein AVD ist eine Gerätekonfiguration für den Android-Emulator die dir erlaubt verschiedene Gerätekonfigurationen abzubilden.
Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable, then execute:</translate>
[[Datei:Avds-config.png|thumb|Der AVD Manager mit ein paar virtuellen Geräten]]
adb install app/build/outputs/MyFirstApp-debug.apk
Ein AVD erzeugen:
<translate>
<!--T:14-->
On your device, locate ''MyFirstApp'' and open it.


# Starte den Android Virtual Device Manager:
<!--T:15-->
## In Eclipse wähle '''Window > AVD Manager''', oder klicke auf das ''AVD Manager''-Symbol in der Eclipse-Werkzeugleiste.
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]].
## In der Kommandozeile wechsle in das Verzeichnis <code><sdk>/tools/</code> führe folgenden Befehl aus:<pre>./android avd</pre>
# Klicke im Fenster des ''Android Virtual Device Device Manager'' auf '''New'''.
# Trage die Details für das AVD ein. Gib einen Namen, eine Zielplattform, die Größe der SD-Karte und einen Skin (Standard ist HVGA) ein.
# Klicke auf '''Create AVD'''.
# Wähle das AVD im ''Android Virtual Device Manager'' und klicke auf '''Start'''.
# Nachdem der Emulator gestartet hat, entsperre den Emulatorbildschirm.


Um die [[App]] aus Eclipse heraus auszuführen, musst du eine Datei deines Projektes öffnen und in der Symbolleiste auf '''Run ''' klicken. Eclipse installiert die [[App]] auf dem angeschlossenen Gerät und startet sie.
== Run on the Emulator == <!--T:16-->
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.
[[Datei:Avds-config.png|thumb|'''Figure 1.''' The AVD Manager main screen shows your current virtual devices.]]


Wenn du statt Eclipse die Kommandozeile verwendest, führe folgende Schritte aus:
=== Create an AVD === <!--T:17-->
# Wechsle in das Stammverzeichnis von deinem Android Projekt und führe <pre>ant debug</pre> aus
# Launch the Android Virtual Device Manager:
# Stelle sicher dass das Android-SDK /plattform-tools-Verzeichnis in deinen PATH-Umgebungsvariablen enthalten ist, und führe <pre>adb install bin/MyFirstApp-debug.apk</pre> aus
#* In Android Studio, select '''Tools > Android > AVD Manager''', or click the AVD Manager icon in the toolbar.
# Suche auf deinem Gerät nun die [[App]] ''MyFirstActivity'' und starte sie
#* Or, from the command line, change directories to <code>sdk/</code> and execute:</translate>
#: <code>tools/android avd</code>
#: <translate><!--T:18-->
'''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.
# On the AVD Manager main screen (figure 1), click '''Create Virtual Device'''.
# In the Select Hardware window, select a device configuration, such as Nexus 6, then click '''Next'''.
# 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].


Weiter geht es mit dem [[Android Training/ Eine einfache Benutzeroberfläche erstellen|Nächsten Schritt]].
=== Run the app from Android Studio === <!--T:19-->
# 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.


{{Android Training/ Vorlage:Attribution}}
=== Run your app from the command line === <!--T:20-->
# 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}}
[[Kategorie:Android Training]]
[[Kategorie:Android Training]]

Aktuelle Version vom 18. Dezember 2015, 22:16 Uhr

Sprachen:

If you followed the 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.

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[Bearbeiten | Quelltext bearbeiten]

If you have a device running Android, here's how to install and run your app.

Set up your device[Bearbeiten | Quelltext bearbeiten]

  1. 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 OEM USB Drivers document.
  2. 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 toSettings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.

Run the app from Android Studio[Bearbeiten | Quelltext bearbeiten]

  1. Select one of your project's files and click Run from the toolbar.
  2. 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[Bearbeiten | Quelltext bearbeiten]

Open a command-line and navigate to the root of your project directory. Use Gradle to build your project in debug mode, invoke the assembleDebug build task using the Gradle wrapper script (gradlew assembleRelease).

This creates your debug .apk file inside the module build/ directory, named MyFirstApp-debug.apk.

On Windows platforms, type this command:

> gradlew.bat assembleDebug

On Mac OS and Linux platforms, type these commands:

$ chmod +x gradlew
$ ./gradlew assembleDebug

After you build the project, the output APK for the app module is located in app/build/outputs/apk/

Note: The first command (chmod) adds the execution permission to the Gradle wrapper script and is only necessary the first time you build this project from the command line.

Make sure the Android SDK platform-tools/ directory is included in your PATH environment variable, then execute:

adb install app/build/outputs/MyFirstApp-debug.apk

On your device, locate MyFirstApp and open it.

That's how you build and run your Android app on a device! To start developing, continue to the next lesson.

Run on the Emulator[Bearbeiten | Quelltext bearbeiten]

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.

Figure 1. The AVD Manager main screen shows your current virtual devices.

Create an AVD[Bearbeiten | Quelltext bearbeiten]

  1. Launch the Android Virtual Device Manager:
    • In Android Studio, select Tools > Android > AVD Manager, or click the AVD Manager icon in the toolbar.
    • Or, from the command line, change directories to sdk/ and execute:
    tools/android avd
    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.
  2. On the AVD Manager main screen (figure 1), click Create Virtual Device.
  3. In the Select Hardware window, select a device configuration, such as Nexus 6, then click Next.
  4. Select the desired system version for the AVD and click Next.
  5. Verify the configuration settings, then click Finish.

For more information about using AVDs, see Managing AVDs with AVD Manager.

Run the app from Android Studio[Bearbeiten | Quelltext bearbeiten]

  1. In Android Studio, select your project and click Run from the toolbar.
  2. In the Choose Device window, click the Launch emulator radio button.
  3. 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[Bearbeiten | Quelltext bearbeiten]

  1. Build the project from the command line. The output APK for the app module is located inapp/build/outputs/apk/.
  2. Make sure the Android SDK platform-tools/ directory is included in your PATH environment variable.
  3. Execute this command:
    adb install app/build/outputs/MyFirstApp-debug.apk
  4. 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 next lesson.