Analysis of build.gradle file format in Android studio_to be continued

        Unlike Eclipse, Android Studio uses Gradle to build projects. Gradle is a very advanced and powerful project building tool. It uses a specific language (DSL) based on the Groovy domain to declare project settings, and abandons various cumbersome configurations based on XML (such as Ant and Maven). Next, we Let's discuss Gradle, a powerful project building tool in Android Studio.

1. Introduction

The new project of Android studio generally contains two build.gradle files, one in the project directory and the other in the app directory, as shown in the figure below.

 

Second, the file format is explained in detail

2.1 The build.gradle file in the project directory

buildscript {
    repositories {
        //代码托管仓库,很多开源Android项目都将代码托管到jcenter()上,声明此配置后,即可引用 
        //jcenter()上的任何开源项目。同时也可以声明其他托管仓库。
        jcenter()
        //添加maven库地址
        maven{
            url "http://maven.xxx.com/xxx/xxx/xxx"
            credentials {
                username 'xxx'
                password 'xxx'
            }
        }
    }
    dependencies {
        //Gradle 插件及使用版本
        classpath 'com.android.tools.build:gradle:2.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
 
allprojects {
    repositories {
        //代码托管仓库
        jcenter()
    }
}
// 运行gradle clean时,执行此处定义的task。
// 该任务继承自Delete,删除根目录中的build目录。
// 相当于执行Delete.delete(rootProject.buildDir)
task clean(type: Delete) {
    delete rootProject.buildDir
}

2.2 The build.gradle file in the app directory

//表明是应用程序的插件,若为库模块,则是'com.android.library'
apply plugin: 'com.android.application'
 
//Android 闭包
android {
    //指定项目的编译版本
    compileSdkVersion 25
    //指定项目的构建工具版本
    buildToolsVersion "25.0.3"
    defaultConfig {
        //指定项目的包名
        applicationId "com.example.qiudengjiao.contentprovider"
        //指定项目最低兼容的 Android 版本
        minSdkVersion 15
        //指定项目的最高兼容 Android 版本
        targetSdkVersion 25
        //指定项目的版本号
        versionCode 1
        //指定项目的版本名
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            //指定是否对项目的代码进行混淆(true:混淆 false:不混淆)
            minifyEnabled false
            //proguardFiles用于指定混淆时使用的规则文件
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

Compiled version, minimum version, target version

compiledSdkVersion: The compiled SDK version is the platform version on which the APP will be compiled. By default it should be set to the latest available version of Android in the SDK. We can still compile the app to support earlier versions, but setting it to the latest version allows us to use new features and optimize the app to have a better user experience on the latest version.


minSdkVersion: It is the "MinimumSDK version" specified when creating a new project. It represents the earliest version of the Android SDK that the app can support, meaning that the normal operation of the app is not guaranteed on Android systems smaller than this version.


targetSdkVersion: Indicates the highest Android version that the developer has tested. When a new version of Android is available, we should test our APP on the new version and update this value to match the latest version of the API, so as to use the new version's functions.

Platform version number API level VERSION_CODE (code name) release time
Android 9.0 28 Pie (pie August 2018
Android 8.1 27 Oreo December 2017
Android 8.0 26 Oreo August 2017
Android 7.1.1 25 Nougat (Nougat) October 2016
Android 7.0 24 Nougat (Nougat) August 2016
Android 6.0 23 Marshmallow (Marshmallow) October 2015
Android 5.1 22 Lollipop (lollipop) March 2015
Android 5.0 21 Lollipop (lollipop) November 2014
Android 4.4W 20 KITKAT_WATCH June 2014
Android 4.4 19 KitKat October 2013
Android 4.3 18 Jelly Bean July 2013
Android 4.2、4.2.2 17 Jelly Bean November 2012
Android 4.1、4.1.1 16 Jelly Bean July 2012
Android 4.0.3、4.0.4 15 Ice Cream Sandwich December 2011
Android 4.0、4.0.1、4.0.2 14 Ice Cream Sandwich October 2011
Android 3.2 13 Honeycomb July 2011
Android 3.1.x 12 Honeycomb May 2011
Android 3.0.x 11 Honeycomb February 2011
Android 2.3.4、2.3.3 10 Gingerbread (gingerbread)

February 2011 

Android 2.3.2、2.3.1、2.3 9 Gingerbread (gingerbread) December 2010
Android 2.2.x 8 Froyo (frozen yogurt) May 2010
Android 2.1.x 7 Eclair (puffs) January 2010
Android 2.0.1 6 Eclair (puffs) December 2009
Android 2.0 5 Eclair (puffs) October 2009
Android 1.6 4 Donut September 2009
Android 1.5 3 Cupcake April 2009
Android 1.1 2 BASE_1_1 February 2009
Android 1.0 1 BASE September 2008

 

 

 


 

Guess you like

Origin blog.csdn.net/wishxiaozhu/article/details/103045328