Android Training/Creating an Android Project/de: Unterschied zwischen den Versionen

Aus Android Wiki
(Die Seite wurde neu angelegt: „Ein Tab für diese Datei erscheint dann in Android Studio, wenn der neue Projekt-Ablauf abgeschlossen wird. Wenn du die Datei auswählst, siehst du die Klassen…“)
(Die Seite wurde neu angelegt: „Die [http://developer.android.com/guide/topics/manifest/manifest-intro.html Manifest Datei] beschreibt die fundamentalen Charakteristiken der App und definiert…“)
 
Zeile 28: Zeile 28:
* Ein Tab für diese Datei erscheint dann in Android Studio, wenn der neue Projekt-Ablauf abgeschlossen wird. Wenn du die Datei auswählst, siehst du die Klassen-Definition für die Activity, welche du erstellt hast. Wenn du die App kompilierst und startest, wird die <code>Activity</code> Klasse die Aktivität starten und das Layout laden, welches "Hello World!" sagt.
* Ein Tab für diese Datei erscheint dann in Android Studio, wenn der neue Projekt-Ablauf abgeschlossen wird. Wenn du die Datei auswählst, siehst du die Klassen-Definition für die Activity, welche du erstellt hast. Wenn du die App kompilierst und startest, wird die <code>Activity</code> Klasse die Aktivität starten und das Layout laden, welches "Hello World!" sagt.
<code>app/src/main/AndroidManifest.xml</code>
<code>app/src/main/AndroidManifest.xml</code>
* The [http://developer.android.com/guide/topics/manifest/manifest-intro.html manifest file] 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.
* Die [http://developer.android.com/guide/topics/manifest/manifest-intro.html Manifest Datei] beschreibt die fundamentalen Charakteristiken der App und definiert jede ihrer Komponenten. Du wirst diese Datei erneut ansehen, wenn du den Übungen folgst und weitere Komponenten zu deiner App hinzufügst.
<code>app/build.gradle</code>
<code>app/build.gradle</code>
* Android Studio uses Gradle to compile and build your app. There is a <code>build.gradle</code> file for each module of your project, as well as a <code>build.gradle</code> file for the entire project. Usually, you're only interested in the<code>build.gradle</code> file for the module, in this case the <code>app</code> or application module. This is where your app's build dependencies are set, including the <code>defaultConfig</code> settings:
* Android Studio uses Gradle to compile and build your app. There is a <code>build.gradle</code> file for each module of your project, as well as a <code>build.gradle</code> file for the entire project. Usually, you're only interested in the<code>build.gradle</code> file for the module, in this case the <code>app</code> or application module. This is where your app's build dependencies are set, including the <code>defaultConfig</code> settings:

Aktuelle Version vom 30. Dezember 2015, 20:48 Uhr

Sprachen:

Ein Android Projekt enthält alle Dateien, die den Source-Code deiner Android App enthalten.

Diese Lektion zeigt dir, wie du ein neues Projekt entweder mit dem Android Studio oder mit der Kommandozeile mit Hilfe der SDK Tools erstellen kannst.

Hinweis: Du solltest bereits das Android SDK, sowie, wenn du Android Studio verwendest, auch das Android Studio, installiert haben. Sollte dies nicht der Fall sein, folge dem Handbuch Installing the Android SDK, bevor du mit dieser Lektion startest.

Ein Projekt mit Android Studio erstellen

Abbildung 1. Konfigurieren eines neuen Projektes in Android Studio.
  1. Erstelle ein neues Projekt in Android Studio:
    • Wenn du kein Projekt geöffnet hast, klicke auf Neue Projekt in der Willkommen Ansicht.
    • Wenn du ein Projekt geöffnet hast, klicke Neues Projekt im Datei-Menü.
  2. Fülle die Felder unter Konfiguriere dein neues Projekt wie in Abbildung 1 gezeigt aus und klicke Weiter. Es ist wahrscheinlich einfacher den Übungen zu folgen, wenn du die gleichen Werte, wie gezeigt, nutzt.
    • Applikations-name ist der Name der App, wie er für die Nutzer erscheint. Für dieses Projekt, nutze "My Frist App."
    • Unternehmensname stellt einen Kennzeichner zur Verfügung, welcher an den Paket-Namen angehängt wird; Android Studio wird sich diesen Kennzeichner für jedes neue Projekt merken, das du erstellst.
    • Paketname ist der voll qualifizierte Name für das Projekt (den gleichen Regeln folgend, wie für die Namensgebung von Paketen in der Java Programmiersprache). Dein Paket-Name muss einzigartig über alle installierten Pakete auf dem Android System sein. Du kannst ihn unabhängig vom App Namen oder der Unternehmens-Domain bearbeiten.
  3. Wähle unter Wähle die Bauformen, unter welchen deine App ausgeführt wird das Kontrollkästchen Telefon und Tablet aus.
  4. Für Mindest-SDK, wähle API 8: Android 2.2 (Froyo) aus.
    • Die mindestens benötigte SDK ist die früheste Android Version, welche deine App unterstützt, angezeigt durch den API-Level. Um so viele Geräte wie möglich zu unterstützen, solltest du die niedrigste verfügbare Version auswählen, welche es deiner App erlaubt, ihre Kernfunktionen auszuführen. Wenn eine Funktion deiner App eine neuere Android Version benötigt und nicht kritisch für die Kernfunktionalität deiner App ist, kannst du diese Funktion auch nur dann aktivieren, wenn eine unterstütze Version installiert ist (wie in Verschiedene Plattformversionen unterstützen beschrieben).
  5. Lasse alle anderen Optionen (TV, Wear und Glass) nicht ausgewählt und klicke Weiter.
  6. Unter Eine Activity zu <template> hinzufügen wähle Leere Activity aus und klicke Weiter.
  7. Unter Wähle Optionen für deine neue Datei aus, ändere den Activity Namen zu MyActivity. Den Layout Namen änderst du zu activity_my, und den Titel zu MyActivity. Der Menü-Ressourcen-Name ist menu_my.
  8. Klicke Fertigstellen um das Projekt zu erstellen.

Dein Android Projekt ist jetzt eine Basis-"Hello World"-App, welche einige Standard-Dateien enthält. Nimm dir einen Moment und sieh dir die wichtigsten genauer an: app/src/main/res/layout/activity_my.xml

  • Das ist die XML-Layout-Datei der Activity, die während der Erstellung des Projektes mit Androis Studio erstellt wurde. Dem neuen Projekt-Ablauf folgend, präsentiert Android Studio diese Datei sowohl mit einer Textbasierten Ansicht, wie einer Vorschau der Bildschirm-Oberfläche. Die Datei beinhaltet einige Standard-Einstellungen und ein TextView Element, welches die Nachricht "Hello worls!" anzeigt.

app/src/main/java/com.mycompany.myfirstapp/MyActivity.java

  • Ein Tab für diese Datei erscheint dann in Android Studio, wenn der neue Projekt-Ablauf abgeschlossen wird. Wenn du die Datei auswählst, siehst du die Klassen-Definition für die Activity, welche du erstellt hast. Wenn du die App kompilierst und startest, wird die Activity Klasse die Aktivität starten und das Layout laden, welches "Hello World!" sagt.

app/src/main/AndroidManifest.xml

  • Die Manifest Datei beschreibt die fundamentalen Charakteristiken der App und definiert jede ihrer Komponenten. Du wirst diese Datei erneut ansehen, wenn du den Übungen folgst und weitere Komponenten zu deiner App hinzufügst.

app/build.gradle

  • Android Studio uses Gradle to compile and build your app. There is a build.gradle file for each module of your project, as well as a build.gradle file for the entire project. Usually, you're only interested in thebuild.gradle file for the module, in this case the app or application module. This is where your app's build dependencies are set, including the defaultConfig settings:
    • compiledSdkVersion is the platform version against which you will compile your app. By default, this is set to the latest version of Android available in your SDK. (It should be Android 4.1 or greater; if you don't have such a version available, you must install one using the SDK Manager.) You can still build your app to support older versions, but setting this to the latest version allows you to enable new features and optimize your app for a great user experience on the latest devices.
    • applicationId is the fully qualified package name for your application that you specified during the New Project workflow.
    • minSdkVersion is the Minimum SDK version you specified during the New Project workflow. This is the earliest version of the Android SDK that your app supports.
    • targetSdkVersion indicates the highest version of Android with which you have tested your application. As new versions of Android become available, you should test your app on the new version and update this value to match the latest API level and thereby take advantage of new platform features. For more information, read Supporting Different Platform Versions.
  • See Building Your Project with Gradle for more information about Gradle.

Note also the /res subdirectories that contain the resources for your application: drawable<density>/

  • 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.

layout/

  • 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.

menu/

  • Directory for files that define your app's menu items.

values/

  • 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 displays when you run the default app.

To run the app, continue to the next lesson.

Create a Project with Command Line Tools

If you're not using the Android Studio IDE, you can instead create your project using the SDK tools from a command line:

  1. Change directories into the Android SDK’s sdk/ path.
  2. Execute:
    tools/android list targets
    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 support older versions, but setting the build target to the latest version allows you to optimize your app for the latest devices. If you don't see any targets listed, you need to install some using the Android SDK Manager tool. See Adding SDK Packages.
  3. Execute:
    android create project --target <target-id> --name MyFirstApp \ --path <path-to-workspace>/MyFirstApp --activity MyActivity \ --package com.example.myfirstapp
    Replace <target-id> with an ID from the list of targets (from the previous step) and replace <path-to-workspace> with the location in which you want to save your Android projects.

Tip: Add the platform-tools/ as well as the tools/ directory to your PATH environment variable.

Your Android project is now a basic "Hello World" app that contains some default files. To run the app, continue to the next lesson.