Create Android Project

Source: Internet
Author: User

An Android project contains all the source code in the app.

This article shows you how to create a new project by using the command line in Androidstudio or Sdktool.

Note: you should have installed Androidstudio or ANDROIDSDK, if not, go to the previous article to see it.

Create a project using Android Studio

1. Create a new project using Android Studio:

      • If there are no already open projects, then on the Welcome screen, click Start a new Android Studio project.

      • If you already have a project open, click New Projecton the File menu.

2. In the Configure your new project interface , fill in the appropriate content in the image and click Next.

Several fields are as follows:

      • Application name is the name of the app that is presented to the user. such as "My application"
      • Company Domain Here is the name of the firm, equivalent to a qualifier, will be added to the package name inside; Android Studio will record the name of the company that was entered when the new project was last created.
      • The unique name of the package name project, the so-called bundle name (which needs to follow the Java language's package naming specification). In all apps installed on Android, your package name must be unique. Of course you can manually click edit to modify the default generated package name.
      • the directory location where the project site project resides.

3. Select theform factors your app'll run on interface , select Phone and Tablet.

4.Minimum SDK, select API 10:android 2.3.3 (Gingerbread).

The Minimum SDK is the minimum version of the Android system your app supports, and the API level you can use at coding. To support more devices, you should choose the lowest possible version of the system based on the core features of your app. If there are any features in the app that can only be run on a high-version system but not the core, you can choose to do some version adaptation, which is only enabled when you run a high version. Can be consulted (compatible with different system versions).

5. Leave all remaining options (TV, Wear, and Glass) unchecked, then click Next.

6. In the Add an activity to mobile interface, select Blank activity to click Next. (Here you can select the appropriate activity template according to the project needs)

7. In the Customize the Activity interface, the activity is named mainactivity. The Layout name is activity_mainand the Title is named mainactivity. The menu Resource Name is menu_main.

Activities

Activity is one of the four components of the Android framework. Activity is provided to the user to access your application, and there may be many activity in an app. Applications typically have a primary activity to launch applications to the user when the user chooses something on the interface, for example, when she and other activities perform other tasks in the application. For more information, see activities.

8. Click the Finish button to start creating the app.

At this point your "HelloWorld" app has been created and contains some default files. Please familiarize yourself with some of the more important things:

App/src/main/res/layout/activity_main.xml

When you create a project from Androidstudio, a layout file that corresponds to the activity is automatically generated. In the latest development tools, Android Studio offers two editing modes, the traditional code-editing mode and the visual layout-editing mode. This layout file contains some default settings, adding one TextView 元素,上面显示了一句话 , "Hello world!"

App/src/main/java/com.netease.myapplication/mainactivity.java

After you create a new project through Androidstudio, this workflow completes, and a tab that corresponds to the file appears in the edit window. When you select this file, you can see that the class that corresponds to the activity is created in this file. Finally, when you compile and run the app, the activity class runs and displays "Hello world!" on the screen.

App/src/main/androidmanifest.xml

Manifest file, Chinese literally means a list, which describes the basic features of the application and defines each of its components (refer to Android four components). In the following tutorial, you will keep reviewing the file and adding the various components that we need to add.

App/build.gradle

Android Studio uses Gradle to compile and build our app. corresponding to each module within the project, there is a build.gradle,当然同时也有一个 build.gradle文件对应于完整的一个工程。通常,你只需要关注app和application模块的 build.gradle file. This is where our app compiles, dependencies, and this configuration file contains defaultConfig这样的设置 :

      • compiledSdkVersionThis value indicates which version of the SDK your app compiles with. By default, we generally use the latest version of the SDK, for example here we use 22. (Google official will recommend more than 4.1, so that the adaptation rate is higher; if not installed, use the SDK Manager to install one). You can choose to develop an app that supports older versions such as 2.3.3 or 4.0.3 (via the latter minSdkVersion控制 ), but this setting wants the latest version number, which will give you the most friendly experience on some of the newest devices, and even the code can run different effects on different system versions.
      • applicationIdis the full app package name you defined when you created the project.
      • minSdkVersionThis value is the minimum system version supported by the app mentioned above. It is usually set up when you create a new project.
      • targetSdkVersionIndicates the highest system version ever tested by a developer. With the release of Android update, you should test your app on the latest system version and update this value to match the latest API level. More information can be found in support of multi-platform version development.

For more information on using Gradle to compile your app, refer to building Your Project with Gradle here.

Learning here, you may also find that there is a folder under the project directory /res , which is all the resources that our app project contains:

drawable<density>/
This directory holds drawable objects (such as bitmaps, selector, etc.), and these resources need to be designed to correspond to different screen resolutions, such as Medium-density (MDPI, medium resolution, 320x480), high-density (hdpi , high resolution, 480x800).
layout/
This directory contains the layout files contained in each of the app's interfaces. For example, the layout file Activity_main.xml in mainactivity above.
menu/
This defines all the menu items that need to be used in the app.
values/
This directory contains some other XML files, which contain a collection of resources, such as String, color, and so on. The "Hello world!" in the example above is defined here in the String.xml file.

  So far, using Androidstudio to create an app project is over, and some of the most important structures and documents for app engineering have been explained. Next, to run the created app, refer to the following tutorial.

    Below, you'll use command-line mode to create an app project.

1. If you are not using Androidstudioide, you can use some of the tools provided in the SDK tools in command-line mode to complete the creation work.

2. In the command-line mode, the CD is located in the ANDROIDSDK directory.

Run command:

Tools\android list targets

This command lists the versions of the Android platform that you have downloaded. Find the version you are ready to use to compile your app and remember the corresponding ID number. Google recommends selecting the highest version . You can choose to develop an app that supports older versions such as 2.3.3 or 4.0.3, minSdkVersion控制 but this setting wants the latest version number, so you can get the most friendly experience on some of the newest devices, and even the code can run different effects on different system versions.

If you do not see any devices listed, then you need to download some down with Androidsdkmanager. Refer to adding SDK Packages.

3. Create the project:

Android Create Project--target <target-id>--name myfirstapp--path <path-to-workspace>/myfirstapp-- Activity myactivity--package Com.example.myfirstapp


<target-id>is the SDK target version that you recorded in the previous step to prepare for compilation. <path-to-workspace>is where you are going to put the project in the directory. In the previous step, it was not recommended to just randomly create the project in the SDK root directory. The SDK and workspace are best stored separately in their respective directories.

Tip : You can put the SDK directory platform-tools/ andtools/ 目录添加到系统的环境变量中,然后在操作adb、android等指令的时候就不需要每次打开CMD都必须cd到sdk目录下了。设置环境变量参考这里。

Now that the project has been created through the command-line mode, this project is also a simple app for "Hello World", with some default files, and the file structure is consistent with Androidstudio created above.

Create Android Project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.