Zum Inhalt springen

Android Training/Running Your Application: Unterschied zwischen den Versionen

Diese Seite wurde zum Übersetzen freigegeben
Keine Bearbeitungszusammenfassung
(Diese Seite wurde zum Übersetzen freigegeben)
Zeile 1: Zeile 1:
<languages />
<languages />
<translate>
<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.
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 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.
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 ==
== Run on a Real Device == <!--T:3-->


<!--T:4-->
If you have a device running Android, here's how to install and run your app.
If you have a device running Android, here's how to install and run your app.


=== Set up your device ===
=== 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.
# 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.
# Enable '''USB debugging''' on your device.
Zeile 15: Zeile 18:
#* 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'''.
#* 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 ===
=== Run the app from Android Studio === <!--T:6-->
# Select one of your project's files and click '''Run'''  from the toolbar.
# 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''' .
# 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.
Android Studio installs the app on your connected device and starts it.


=== Run the app from a command line ===
=== Run the app from a command line === <!--T:7-->
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>).
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-->
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>.


<!--T:9-->
On Windows platforms, type this command:</translate>
On Windows platforms, type this command:</translate>
  > gradlew.bat assembleDebug
  > gradlew.bat assembleDebug
<translate>
<translate>
<!--T:10-->
On Mac OS and Linux platforms, type these commands:</translate>
On Mac OS and Linux platforms, type these commands:</translate>
  $ chmod +x gradlew
  $ chmod +x gradlew
  $ ./gradlew assembleDebug
  $ ./gradlew assembleDebug
<translate>
<translate>
<!--T:11-->
After you build the project, the output APK for the app module is located in <code>app/build/outputs/apk/</code>
After you build the project, the output APK for the app module is located in <code>app/build/outputs/apk/</code>


<!--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.
'''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-->
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:</translate>
  adb install app/build/outputs/MyFirstApp-debug.apk
  adb install app/build/outputs/MyFirstApp-debug.apk
<translate>
<translate>
<!--T:14-->
On your device, locate ''MyFirstApp'' and open it.
On your device, locate ''MyFirstApp'' and open it.


<!--T:15-->
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]].
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 ==
== 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.
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.]]
[[Datei:Avds-config.png|thumb|'''Figure 1.''' The AVD Manager main screen shows your current virtual devices.]]


=== 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 Android Studio, select '''Tools > Android > AVD Manager''', or click the AVD Manager icon in the toolbar.
#* Or, from the command line, change directories to <code>sdk/</code> and execute:</translate>
#* Or, from the command line, change directories to <code>sdk/</code> and execute:</translate>
#: <code>tools/android avd</code>
#: <code>tools/android avd</code>
#: <translate>'''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.
#: <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'''.
# 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'''.
# In the Select Hardware window, select a device configuration, such as Nexus 6, then click '''Next'''.
Zeile 59: Zeile 71:
For more information about using AVDs, see [http://developer.android.com/tools/devices/managing-avds.html Managing AVDs with AVD Manager].
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 ===
=== Run the app from Android Studio === <!--T:19-->
# In '''Android Studio''', select your project and click '''Run''' from the toolbar.
# In '''Android Studio''', select your project and click '''Run''' from the toolbar.
# In the '''Choose Device''' window, click the '''Launch emulator''' radio button.
# In the '''Choose Device''' window, click the '''Launch emulator''' radio button.
Zeile 65: Zeile 77:
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.
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 ===
=== 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>.
# 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.
# Make sure the Android SDK <code>platform-tools/</code> directory is included in your <code>PATH</code> environment variable.
# Execute this command:</translate>
# Execute this command:</translate>
#: <code>adb install app/build/outputs/MyFirstApp-debug.apk</code>
#: <code>adb install app/build/outputs/MyFirstApp-debug.apk</code>
# <translate>On the emulator, locate ''MyFirstApp'' and open it.
# <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]].
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>
</translate>
11.008

Bearbeitungen

Cookies helfen uns bei der Bereitstellung von Android Wiki. Durch die Nutzung von Android Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.