Understand Android, understand JDK, SDK, NDK, understand gradle

Android is an open source, Linux-based free and open source operating system. Primarily used on mobile devices such as smartphones and tablets.

Android development environment:

The language used for Android development is JAVA or Kotlin, and the underlying operations use C\C++.
  The tools for Android development mainly include Eclipse or IDEA, and Android Studio. Among them, Android Studio is the officially designated development tool and is recommended. And Eclipse is currently (February 14, 2020) Google no longer supports it. IDEA or Android Studio is recommended.
Notice! Whether it is setting the path of the SDK or setting your project or other, Chinese cannot be used! Also try not to use Chinese as much as possible!

JDK

JDK
  JDK is a compiler for the JAVA language, and its full name is Java Development Kit, which is the Java Development Kit. Because the Android application layer is developed in Java , it runs on the Java virtual machine (Dalvik virtual machine, which is different from the JVM virtual machine).
  It is recommended to install JDK 1.8 or above, because different Android versions have corresponding requirements for JDK. For example, Android 5.0 is compiled with JDK1.7 by default, and Android 7.0 is compiled with JDK1.8 by default.
  If the JDK is 1.6 or 1.78, and the SDK is the latest version, it may cause the following problems.
  (1) After creating the project, an error will be reported when browsing the layout file design drawing and Android N requires the IDE to be running with Java 1.8 or later. (2
  ) Compiling the project fails, prompting an error com/android/dx/command/dexer/Main: Unsupported major.minor version 52.0.
  (3) Failed to run the App, prompting error complieSdkVersion 'android-24' requires JDK 1.8 or later to compile.

SDK

SDK is a compiler for Android applications , and its full name is Software Development Kit, which is a software development kit. The SDK provides a collection of common tools for App development.
insert image description here
It mainly includes:
add-ones directory: stores the service expansion packages provided by Google. (Eclipse exists, and Android Studio has moved to other places.)
build-tools directory: Stores various compilation tools for various versions of Android.
docs directory: store development documentation.
extras directory: stores Android additional support files. There are mainly Android support packages, several tools and drivers from Google, and IntelHaxm from Intel.
platforms directory: store Android resource files of various versions. Including fonts, res resources, templates, etc.
The platform-tools and tools directories store commonly used development aids. very important.
samples directory: stores the demo source codes of common functions of each version of Android.
sources directory: store the API development interface source code of each version of Android.
system-images directory: stores the system images and management tools of each version of the emulator.
emulator directory: stores emulator software.
patcher: store the patch folder. (I don't know what it is, it translates to a patch)
cmake: Stores cross-platform compilation tools for compiling C/C++ code.
ndk : store NDK development tools.
fonts: store fonts.
licenses: Store the verification code of the SDK, and the check code of the SKD is stored in the file.
lldb: stores the c/c++ debugger for NDK debugging.
skins: skin folder, which stores some virtual machine effect pictures.
(Note: The picture is only the newly installed SDK. Some new files will be added to the download later. For example, if the NDK is installed, the ndk folder will exist.)

GDR

NDK is a compiler for C\C++ code, and its full name is Native Development Kit. That is, the native development kit. This tool mainly provides the use of JNI interface. Firstly, the C\C++ code is compiled into so library, and then the Java code calls the so library through the JNI interface.
  Because the Java bytecode is extremely easy to decompile and view the source code, the so library compiled with C\C++ can store some core codes, and the so library and Java bytecode are more difficult to crack. And C\C++ runs faster than Java, and can write some data with a relatively large amount of processing and time-consuming. (For example, audio, video processing operations.

gradle

Simple understanding of Gradle

Gradle is an open source tool for project automation building based on the concepts of Apache Ant and Apache Maven. It uses a Groovy-based domain-specific language (DSL) to declare project settings. It is mainly used to describe the environment required for Android development, manage third-party jar packages, third-party extension libraries, jar dependencies, etc.

Understand the engineering structure of developing App

The project creation of Android Studio is divided into two levels.
The first level is Project (project) , which specifies the workspace of the current project. It is equivalent to Eclipse's workspace.
Project structure diagram
  As can be seen from the figure, there are 4 folders under the project, among which .gradle is used to save the dependency information of gradle, and .idea is used to save the setting information of the development tool.
  And app is the folder we mainly develop, and gradle is the file that stores gradle. We only need to care about the app folder.  However, you still need to know some files in its root directory.
.gitignore file: indicates that git ignores the file list, and the specified folder will not be uploaded to the warehouse.

Account.iml file: It is a file used by the project to save development tool information. Its file name is the project name.

build.gradle file: project-level compilation rule file, used to describe the compilation rules of the entire project.

proguard-rules.pro file: Code obfuscation rules for describing Java files.

gradle.properties file: It is used to configure the command line parameters of the compilation project, and generally does not need to be changed.

gradlew file: Gradle Wrapper, used for the installation and deployment of Gradle itself. It is an executable script under Linux.

gradlew.bat file: Gradle Wrapper, used to install and deploy Gradle itself. It is an executable script under Windows.

local.properties file: Used to describe the environment configuration of the developer's local machine. The specified path of SDK, NDK, etc. is in this file.

settings.gradle file: Configure which modules are compiled together. The initial content is include ':app', which means that only the App module will be compiled.
The second level is Module (module) , which specifies the modules in the current project, where a module refers to a separate App project. But it can also be combined into an App through modular programming. It is equivalent to the Eclipse project.
  In fact, the app folder is a Module. When we create a new Project, we create a default Module. It is the app folder.
insert image description here
From the above Module structure diagram, we can see:
build directory: stores compiled and built files.
libs directory: store third-party jar packages.
src directory: source files.
build.gradle file: the configuration file of the current Module.
Among them, the src directory and the build.gradle file are more important.
It will be explained in detail below.

(app/src)

insert image description here
insert image description here

The src folder contains the androidTest folder, the main folder (important!) , and the test folder.
androidTest directory: Android unit tests. It is primarily concerned with unit testing for Android Instruments.
main directory: development directory.
test directory: unit tests. It does not contain framework tests for Android.
Among them, androidTest and test mainly include the java directory, which contains the corresponding tests.

(app/src/main)

insert image description here
And main is our main development directory. It mainly includes the following:
(1) java directory: mainly stores java files. Under its directory is the package name.

(app/src/main/res)

insert image description here
(2) res directory: Android resource folder. It mainly stores layout resources, picture resources and so on.
res\drawable directory: store graphics description files and user pictures. The following hdpi, mdpi, xhdpi, xxhdpi, etc. all refer to the resolution of the picture, and the corresponding picture should be placed in the corresponding folder.
res\layout directory: store layout files for app pages.
res\mipmap directory: the icon folder of the app. Stores the icon of the app. Like the drawable folder, it has a corresponding resolution folder.
res\values ​​directory: stores some constant definition files. For example, string constant definition string.xml, pixel constant dimens.xml, color constant colors.xml, style styles styles.xml, etc.

(3) AndroidManifest.xml file: Android manifest file. (Important! Specify the run configuration inside it!)

AndroidManifest.xml part description:
  AndroidManifest.xml is used to specify the internal running configuration of the App. It is an XML description file, the root node is manifest, and the package of the root node specifies the package name of the App. There are several sub-nodes under the manifest, which are described as follows.
The content of the app's AndroidManifest.xml file is explained in detail as follows:

<?xml version="1.0" encoding="utf-8"?><!--说明xml文件的版本和编码格式-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dist="http://schemas.android.com/apk/distribution"
    package="com.palz.account"><!--根节点,指定app的包名-->

    <dist:module dist:instant="true" /><!--模块化结点,指定Goolge Play免安装-->
    
    <!--应用根结点-->
    <application 

        <!--允许备份-->
        android:allowBackup="true"

        <!--指定app的启动图标-->
        android:icon="@mipmap/ic_launcher"

        <!--指定app的名称-->
        android:label="@string/app_name"

        <!--指定app的圆形图标-->
        android:roundIcon="@mipmap/ic_launcher_round"

        <!--是否愿意支持从右到左(RTL是right-to-left 的缩写)的布局-->
        android:supportsRtl="true"

        <!--指定app的主题-->
        android:theme="@style/AppTheme">

        <!--活动根结点-->
        <activity android:name=".MainActivity">
            <!--Intent过滤器根结点:只有符合相对应的要求才能通过Intent启动活动-->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

Among them, the nodes that AndroidManifest.xml can contain are:

<?xml version="1.0" encoding="utf-8"?>

<manifest>

    <dist:module>
        <dist:delivery>
          <dist:install-time>
            <dist:conditions>
              <!-- Requires that the device support AR to download the module at
              app install-time.  -->
              <dist:device-feature />
            </dist:conditions>
          </dist:install-time>
        </dist:delivery>
      </dist:module>

    <uses-permission />
    <permission />
    <permission-tree />
    <permission-group />
    <instrumentation />
    <uses-sdk />
    <uses-configuration /> 
    <uses-feature /> 
    <supports-screens /> 
    <compatible-screens /> 
    <supports-gl-texture /> 

    <application>

        <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>

        <activity-alias>
            <intent-filter>. . .</intent-filter>
            <meta-data />
        </activity-alias>

        <service>
            <intent-filter>. . .</intent-filter>
            <meta-data/>
        </service>

        <receiver>
            <intent-filter>. . .</intent-filter>
            <meta-data />
        </receiver>

        <provider>
            <grant-uri-permission />
            <meta-data />
            <path-permission />
        </provider>

        <uses-library />

    </application>

</manifest>

The following introduces several commonly used label nodes:
manifest label:
  manifest label is the root node label of AndroidManifest.xml. It is often used to set some properties related to the project. For example, the package attribute used to uniquely identify the application, the Android:versionName attribute used to record the application version, and so on.
  The xmls:android attribute must be http://schemas.android.com/apk/res/android, and
  the xmlns:dist attribute must be http://schemas.android.com/apk/distribution.
It is used to represent a namespace.
application tag:
   There is only one application tag in the manifest tag. It is used to specify various metadata about the application (including title, icon, and theme). Can also be used as a container for Activity, Service, Provider and Broadcast Receiver tags to indicate application components.
uses-permission tag:
  The uses-permission tag is used to indicate the permissions that the program will use. These permissions are necessary for the application to function properly. .
permission tag: The
  permission tag is used to indicate the permissions that other programs need to access your components . When you provide other functions to other software, other software needs to specify its permission in the manifest file (AndroidManifest.xml) to access Your component function or data.
5. Instrumentation label:
  The instrumentation tag specifies the test class for the instrumentation class. The instrumentation class provides a framework for running tests on an activity or service while the application is running, by which it can be used to monitor the application and its interaction with system resources. Whenever a new test class is added to the application, a new node needs to be added for it.
The directories included in the app are introduced here. Here are a few files in the root directory of the app:

build.gradle file: This file is used for the compilation rules of the App project.
.gitignore file: This file is used to specify the git ignore list, and the files it contains will not be uploaded to the warehouse.
gradle.properties file: This file is used to configure command-line parameters for compiling the project, and generally does not need to be changed.
app.iml file: used to save development tool information. The filename is the current module name.

The most important of these is build.gradle. The following is a brief introduction to the build.gradle file:
  build.gradle is divided into project level and module level. We generally do not need to change the project level, we only need to pay attention to the module level build.gradle . Here's a build.gradle file that I'm currently working on for an app:

apply plugin: 'com.android.application'//指明module的类型,com.android.application为程序,com.android.library为安卓库

android {
    
    
    compileSdkVersion 29//编译的SDK版本
    buildToolsVersion "29.0.3"//编译的Tools版本
    defaultConfig {
    
    
        applicationId "com.palz.account"//应用程序的包名
        minSdkVersion 15 //最低支持的目标版本
        targetSdkVersion 29//当前最高支持的目标版本
        versionCode 1 //版本号
        versionName "1.0"//版本名
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"//安卓测试库
    }
    buildTypes {
    
    //build类型
        release {
    
    //发布
            minifyEnabled false //是否开启混淆代码功能
            //指定代码混淆规则文件的文件名
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    
    //指定App的编译信息
    implementation fileTree(dir: 'libs', include: ['*.jar'])//指定引用jar包的路径
    implementation 'androidx.appcompat:appcompat:1.1.0'//引用appcompat库
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'//引用constrainlayout库
    testImplementation 'junit:junit:4.12'//指定单元测试编译用的版本号
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'//指定安卓测试编译用的版本号
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'//使用Espresso的进行测试的版本号
}

Android Code Generator quickly generates the corresponding Activity, Fragment, Adapter, and Menu classes according to the layout file.

CodeGlance : Quickly preview the code on the right for quick positioning.

ECTranslation : translation software.

A collection of useful plugins for Android Studio

Guess you like

Origin blog.csdn.net/qq_45926254/article/details/129626766