Android official Getting Started document [1] Creating an Android project
Create an Android project
This lesson teaches you
1. Create a project with Android studio
2. Create a project using the command line tool
You should also read
? Manage projects
Creating an Android Project
This lesson teaches
1.Create a Project with Android Studio
2.Create a Project with Command line Tools
You should also read
? Managing Projects
An Android project contains all the source code files that make up your Android app.
This lesson shows how to use Android Studio or create a new project on the command line using the SDK tools.
Note: You should have installed the Android SDK, and if you are using Android Studio, you should also install Android Studio. If you do not have these, follow the instructions to install the Android SDK before starting this lesson.
An Android project contains all the files of the comprise the source code for your Android app.
This lesson shows how to create a new project either using Android Studio or using the SDK tools from a command line.
Note:you should already has the Android SDK installed, and if you ' re using Android Studio, you should also has Android Studio installed. If you don't have these, follow the "guide" to installing the Android SDK before your start this lesson.
Create an Android studio project
Create a Project with Android Studio
--------------------------------------------------------------------------------
1. In Android Studio, create a new project:? If you do not have a project open, on the Welcome screen, click New Project.
? If you have a project open, from the File menu, select New Project.
1.In Android Studio, create a new project:? If you don has a project opened, in the Welcome screen, click New Project.
? If you had a project opened, from the File menu, select New Project.
Figure 1. A new project in the configuration of Android Studio.
Figure 1. Configuring a new project in Android Studio.
2. In Configure your new project, fill in the fields shown in field 1, and then click Next.
It may be easier to follow these lessons if you use the same values.
The application name is the name of the application that appears to the user. For this project, use "My first application." ”
The company domain offers to be appended to the package name eligibility tournament; Android Studio will remember this qualifier for every new item you create.
The package name is the full name of the project (which follows the same rules in the Java programming language-named Package). Your package name must be unique on all packages installed on the Android system. You can edit this value independently from the name of the application or from the company domain.
The location of the project is the directory where your system saves the project files.
2.Under Configure your new project, fill in the fields as shown in Figure 1 and click Next.
It'll probably be easier to follow these lessons if you use the same values as shown.
? Application name is the app name, appears to users. For this project, use "My first App."
? Company Domain provides a qualifier that'll be appended to the package name; Android Studio would remember this qualifier for each new project you create.
? Package name was the fully qualified name for the project (following the same rules as those for naming packages in the Jav A programming language). Your Package name must is unique across all packages installed on the Android system. You can Edit this value independently from the application name or the company domain.
? Project location is the directory on your system, holds the project files.
3. In the Select Profile your app will run, check the box for the phone and tablet.
3.Under Select The form factors your app would run on to check the box for Phone and Tablet.
4. For the smallest SDK, select API 8:android 2.2 (upgrade Froyo). The minimum SDK required for the
is an earlier version of Android, supported by your application, using the API level representation. In order to support as many devices as possible, you should set it as available to let your application to provide the minimum version of its core feature set. If any feature in your application can only be in the newer version of Android, it is not the key to the core feature set of the application, and you can enable it to run on versions that support it (discussed in support of different platform versions) only if that feature is available.
4.For Minimum SDK, select API 8:android 2.2 (Froyo).
The Minimum Required SDK is the earliest version of Android that your app supports, indicated using the API leve L. To support as many devices as possible, you should set this to the lowest version available that allows your app to Provid E its core feature set. If any feature of your app was possible only on newer versions of Android and it's not critical to the app ' s core feature S ET, you can enable the feature if running on the versions, it (as discussed in supporting Differe NT Platform Versions).
5. Select all other options (TV, wear and glass), and then click Next.
5.Leave all of the other options (TV, Wear, and Glass) unchecked and click Next.
Activities
Activities
Activity is one of the notable features of the Android framework. Activities provide users with access to your application, and there may be many activities. An application will typically have the primary activity of other activities when the user launches the application when she chooses some content to view, for example for another activity, and when she performs other tasks in the app. See the details of the activity.
An activity is one of the distinguishing features of the Android framework. Activities provide the user with access to your app, and there may be many activities. An application would usually has a main activity for when the user launches the application, another activity for when she Selects some content to view, for example, and other activities for when she performs other tasks within the app. See activities for more information.
6. In Add an active project, select the blank activity, and then click Next.
6.Under Add an activity to your project, select Blank activity and click Next.
7. In describing the new activity items, leave the field as they are and click Finish.
7.Under Describe The new activity for your project, leave the fields as they is and click Finish.
Your Android project is now a basic "Hello world" application that contains some of the default files. Take a moment to review the most important:
Your Android Project is now a basic ' Hello world ' app that contains some default files. Take a moment to review the most important of these:
app/src/main/res/layout/activity_my.xml
This is for you to add when you create android The XML layout file for the project activity in studio. Following the workflow of the new project, Android Studio introduces the file with a preview of both the text view and the screen UI. The file includes some default settings and displays the message, a textview element of "the World, Hello!" "
This is the XML layout file for the activity you added when you created the project with Android Studio. Following the New Project workflow, Android Studio presents this file with both a text view and a preview of the screen UI . The file includes some default settings and a TextView element that displays the message, "Hello world!"
App/src/main/java/com.mycompany.myfirstapp/myactivity.java
The File tab appears in Android studio when a new project's workflow is completed. When you select the file, you see the class definition of the activity you created. When you build and run the application, the activity class begins activity and loads the layout file, which reads "Hello world! ”
A tab for this file, appears in Android Studio, when the New Project workflow finishes. When you select the file, you see the class definition for the activity created. When you build and run the app, the activity class starts the activity and loads the layout file that says "Hello world!"
App/src/res/androidmanifest.xml
The manifest file describes the basic characteristics of the application and identifies each of its components. When you follow these lessons, you will discuss this file again and add more components to you
The manifest file describes the fundamental characteristics of the app and defines each of their components. You'll revisit this file as you follow these lessons and add more components to your
App.app/build.gradle
Android Studio uses Gradle to compile and build its own applications. There are build.gradle files for each module in the project, as well as for the entire project Build.gradle file. Typically, you only care about the module's Build.gradle file, in this case, the application or application module. This is the build dependency setting for your application, including the Defaultconfig settings:
? Compiledsdkversion is the platform version to which you will compile your application. By default, it is set to the latest version of the Android system in your SDK. (This should be Android 4.1 or later; if there is no such version, you must install one using the SDK manager.) You can also build your own app to support older versions, but this setting to the latest version allows you to enable new features and optimized apps for the latest device user experience.
? ApplicationID is the fully qualified package name of the application that you specified in the new project workflow.
? Minsdkversion is the new project workflow for the minimum SDK version you specified. This is the earliest version of your app that supports the Android SDK.
? Targetsdkversion represents the highest version of Android with which you have tested your application. As new versions of Android are available, you should test the new version of your application and update this value to match the latest API levels to take on new platform features. For more information, please read support for different platform versions.
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 the Build.gradle file for the module, in this case the app or application module. This is where your app's build dependencies is set, including the Defaultconfig settings:? compiledsdkversion Form version against which you'll compile your app. By default, this is set to the latest version of the Android available in your SDK. (It should is Android 4.1 or greater; If you don't have such a version available, you must install one using the SDK manag Er.) You can still build your app. older versions, but setting the latest version allows your to enable new FE Atures and optimize your app for a great user experience on the latest devices.
ApplicationID is the fully qualified package name for your application so you specified during the New Project workflow .
Minsdkversion is the Minimum SDK version of 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 th E latest API level and thereby take advantage of new platform features. For more information, read supporting Different Platform Versions.
See the build project for more information about gradle with Gradle.
See Building Your Project with Gradle For more information about Gradle.
Note also the/res subdirectories that contain the resources for your application:
Also note is the resource/RES subdirectory that contains the application:
drawable-hdpi/
The catalog can draw objects (such as bitmaps) which are designed for high density (hdpi) screens. Other drawing catalogs contain assets specifically designed for other screen densities. Here you will find that when you run the default display of the Ic_launcher.png
Directory for drawable objects (such as bitmaps), that is designed for high-density (hdpi) screens. Other drawable directories contain assets designed for other screens densities. Here you'll find the ic_launcher.png that appears when you run the default
app.layout/
The directory defines the user interface of your application as Activity_my.xml, as discussed above, which describes the basic layout files of the MyActivity class.
Directory for files that define your app's user interface like Activity_my.xml, discussed above, which describes a basic l Ayout for the MyActivity class.
values/
The catalog contains a collection of resources for other XML files, such as the definition of strings and colors. The "Hello world!" file definition in Strings.xml "String when you run the default application display.
To run the application, continue to the next lesson. ...
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 using the command line tool
Create a Project with Command line Tools
-------------------------------------------------- ------------------------------
If you do not use the Android Studio IDE, you can use the SDK tools to create the project from the command line:
If you're not using the the Android Studio IDE, you can instead create your project using the SDK tools from a command line:
1. Change the directory to the tools/path of the Android SDK.
1.Change directories into the Android SDK ' s tools/path.
2.execute:android's target list
2.execute:android list targets
This will print and you have downloaded the list of available Android platforms for your SDK. Locate the platform on which you want to compile your application. Note The ID of the target. We recommend that you select the highest possible version. You can still build your own app to support older versions, but build target settings to the latest version, you can optimize your application's latest device.
This prints a list of the available Android platforms so 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. older versions, but setting the build target to the latest version allows your to O Ptimize your app for the latest devices.
If you don't see any of the targets listed, you'll need some installation using the Android SDK Manager tool. See Add SDK Packages.
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
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 the target list (from the previous steps) of the ID and replace < path to workspace > with the location where you want to save your Android project.
Replace <target-id> with a ID from the list of targets (from the previous step) and replace <PATH-TO-WORKSPACE&G T With the location of which you want to save your Android projects.
Tip: Add the Platform tools/and tools/directories to the PATH environment variable.
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" application that contains some of the default files. To run the application, continue to the next lesson.
Your Android Project is now a basic ' Hello world ' app that contains some default files. To run the app, continue to the next lesson.
This article is translated from: https://developer.android.com/training/basics/firstapp/creating-project.html
Android official Getting Started document [1] Creating an Android project