Android Road (ii)

Source: Internet
Author: User
Tags jcenter

(a) In-app document detailed

1. Build contains files that are automatically generated at compile time.

2. Libs Third party jar package , need to put the jar package in Libs, will be automatically added to the build path.

3. Androidtest here is a test case for Android test, you can do some automated testing of the project

4. Where Java code is placed, the activity file is inside.

5. All the images/layouts/strings used in the RES project are stored in this directory. The picture is placed in the drawable directory, the layout is placed in the layouts directory, and the string is placed in the values directory.

6. Androidmanifest.xml

The entire Android project configuration file, all four components defined in the program need to be registered in this file , you can also add a permission statement to the application in this file.

7. Test is used to write the Unit test test case, which is another way to automate the detection of a project.

8.. gitignore excludes the specified directory or file within the app module from version control , and is similar to the outer. Gitignore file.

9. APP.IML IntelliJ Idea Auto-generated files

The gradle build script for the Build.gradle app module, which specifies many projects to build related configurations.

Proguard-rules.pro is used to specify the obfuscation rules for the project code, and when the code is developed, it is made into an installation package file, which often confuses the code if you do not want the code to be cracked by others.

(ii) Code analysis

Androidmanifest.xml, the two lines of code in Intent-filter are very important to register the activity.

<action android:name= "Android.intent.action. MAIN"/> and <category android:name=" android.intent.category. LAUNCHER"/> said Helloworldactivity is the main activity of the project, click on the app icon on the phone, the first thing to start is this activity.

In Activity.java,

Activity is an active base class provided by the Android system, and all activities in our project must inherit it or its subclasses to have an active attribute (Appcompatactivity is a subclass of activity).

There is a onCreate () method in Helloworldactivity, which is a method that must be executed when an activity is created.

The second line of the OnCreate () method calls the Setcontentview () method, which introduces a hello_world_layout to the current activity.

(iii) resources in the project

drawable picture, mipmap icon, values string style color configuration, layout file

The reason why there are so many mipmap opening folders, in fact, is mainly to allow the program to better compatible with a variety of devices. Drawable folder is the same, although Android Studio does not help us to generate automatically, but we should create the drawable-hdpi, drawable-xhdpi, drawable-xxhdpi and other folders

Res/values/strings.xml two ways to quote:

1. R.string.app_name 2 in the code. @string/app_name string in XML can be replaced by drawable mipmap layout, and so on.

androidmanifest.xml The app icon is specified by Android:icon, the app name Android:label specified. Modify the icon or name here.

(iii) Build.gradle file

Android Studio uses Gradle to build the project. Gradle is a very advanced project building tool that uses a groovy-based domain-specific language DSL to declare project settings, eliminating the cumbersome configuration of traditional XML-based such as Ant and Maven. There are two build.gradle files, one on the outermost one in the app.

Outside (if you want to add some global project build configuration, you can change it):

The jcenter () line configuration is declared in both repositories closures . It is a code-managed warehouse . Many Android open source projects will choose to host the code on the Jcenter, and after declaring this line of configuration, we can easily reference any open source project on the Jecenter in the project.

A gradle plugin was declared using Classpath in the dependencies closure. Because Gradle is not specifically built for Android projects, java,c++ and many other projects can be built using Gradle. So if we want to use it to build Android to declare, Com.android. Tools.build:gradle: Version number

In app:

The first line applies a plug-in apply plugin, there are generally two values to choose from:com.android.application Indicates that this is an application module com.android.library indicates that this is a library module. The biggest difference between an application module and a library module is that one can be run directly, and one should only be attached to another application module as a code base.

Next is an Android closure that configures the various properties of the project build.

compilesdkversion is used to specify the compiled version of the project, which is specified here as 24 for the SDK compilation using the Android 7.0 system

buildtoolsversion for specifying the version of the Project build tool

defaultconfig closures nested in Android closures

ApplicationID is used to specify the package name of the project, we have already specified the package name when we created the project, and if you want to modify it later, you will change it here .

minsdkversion is used to specify the minimum compatible Android version of the project, 15 for minimum compatibility to Android 4.0 systems

The value specified by targetsdkversion indicates that you have done sufficient testing on the target version, and the system will enable some of the latest features and features for your application.    For example, the Android 6.0 system introduces runtime permissions, if you assign targetsdkversion to 23 or higher, then the system will enable the runtime permissions function for your program, and if you specify targetsdkversion to 22, then It means that your program is only fully tested on Android 5.1, and the new features introduced in the Android 6.0 system will naturally not be enabled.

versioncode used to specify the version number of the project,versionname to specify the version name of the project

buildtypes closure , which specifies the configuration of the build installation file. Usually there will be only two word closures, debug and release. Debug is used to specify the configuration for generating a beta installation file, which specifies the configuration to generate the official version of the installation file.

Not finished ...

Android Road (ii)

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.