Android Training/Running Your Application/de: Unterschied zwischen den Versionen

Aus Android Wiki
(Die Seite wurde neu angelegt: „=== Starten der App aus Android Studio === # Wähle eine deiner Projektdateien aus und klicke '''Start''' in der Toolbar. # In dem '''Wähle Gerät''' Fenster,…“)
(Die Seite wurde neu angelegt: „=== Starten der App von der Kommandozeile === Öffne ein Kommandozeilen-Fenster und navigiere zum Stammverzeichnis deines Projektes. Verwende Gradle um dein Pr…“)
Zeile 19: Zeile 19:
# In dem '''Wähle Gerät''' Fenster, welches erscheint, wähle das '''Wähle ein gestartetes Gerät''' Auswahlfeld aus, selektiere dein Gerät und klicke '''OK'''.
# In dem '''Wähle Gerät''' Fenster, welches erscheint, wähle das '''Wähle ein gestartetes Gerät''' Auswahlfeld aus, selektiere dein Gerät und klicke '''OK'''.


=== Run the app from a command line ===
=== Starten der App von der Kommandozeile ===
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>).
Öffne ein Kommandozeilen-Fenster und navigiere zum Stammverzeichnis deines Projektes. Verwende Gradle um dein Projekt im Debug-Modus zu erstellen, indem du die <code>assembleDebug</code> Build-Aufgabe mit dem Gradle wrapper Script (<code>gradlew assembleRelease</code>) nutzt.


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

Version vom 18. Dezember 2015, 22:10 Uhr

Sprachen:

Wenn du der vorherigen Übung gefolgt bist um ein Android Projekt zu erstellen, enthält es standardmäßig einige "Hello World" Quellcode-Dateien, welche es dir erlauben die App sofort zu starten.

Wie du deine App startest hängt von zwei Dingen ab: Ob du ein real vorhandenes Gerät mit Android hast und ob du Android Studio verwendest. Diese Übung zeigt dir, wie du deine App auf einem realen Gerät und im Android Emulator installierst und startest, sowohl mit Android Studio, als auch mit den Kommandozeilen-Tools.

Auf einem realen Gerät ausführen

Wenn du ein Gerät hast, auf welchem Android installiert ist, findest du hier die Schritte, wie du deine App installierst und startest.

Gerät vorbereiten

  1. Verbinde dein Gerät mit einem USB-Kabel mit deinem Entwicklungs-Rechner. Wenn du unter Windows entwickelst benötigst du ggf. die richtigen USB-Treiber für dein Gerät. Für Hilfe zur Installation der Treiber, siehe das OEM USB Drivers Dokument.
  2. Aktiviere USB Debugging bei deinem Gerät.
    • Bei den meisten Geräten, welche Android 3.2 oder älter installiert haben, findest du die Option unter EInstellungen > Apps > Entwicklung.
    • In Android 4.0 oder neuer, ist die EInstellung in Einstellungen > Entwickleroptionen zu finden.
    Hinweis: In Android 4.2 und neuer sind die Entwickleroptionen standardmäßig versteckt. Um diese verfügbar zu machen, gehe zu Einstellungen > Über das Telefon und tippe sieben mal auf Build Nummer. Kehre dann zurück zur vorherigen Ansicht um Entwickleroptionen zu finden.

Starten der App aus Android Studio

  1. Wähle eine deiner Projektdateien aus und klicke Start in der Toolbar.
  2. In dem Wähle Gerät Fenster, welches erscheint, wähle das Wähle ein gestartetes Gerät Auswahlfeld aus, selektiere dein Gerät und klicke OK.

Starten der App von der Kommandozeile

Öffne ein Kommandozeilen-Fenster und navigiere zum Stammverzeichnis deines Projektes. Verwende Gradle um dein Projekt im Debug-Modus zu erstellen, indem du die assembleDebug Build-Aufgabe mit dem Gradle wrapper Script (gradlew assembleRelease) nutzt.

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

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

  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

  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

  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.