1. 程式人生 > >app目錄下的build.gradle詳解

app目錄下的build.gradle詳解

主要參考自《第一行程式碼》
// 表示這是一個Android程式模組,如果是作為庫,就宣告為Library'com.android.library'
apply plugin: 'com.android.application'

android {
    compileSdkVersion 26 // 編譯版本,指用哪個版本的SDK進行編譯
    buildToolsVersion "26.0.1" //構建工具
    //對專案的更多細節進行配置
    defaultConfig {
        applicationId "com.seachal.myapplicationtestlog"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    //指定生成安裝檔案的相關配置
    buildTypes {
        //release 閉包用於指定生成正式版安裝檔案的配置
        release {
            minifyEnabled false //指定是否對專案的程式碼進行混淆, true 表示混淆, false 表示不混淆。
            //proguard-android.txt在預設的SDK目錄下,有通用的混淆規則
            // proguard-rules.pro 有本專案專用的混淆規則
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        //debug閉包可以忽略不寫
    }
}

dependencies {
    //本地依賴宣告,它表示將 libs 目錄下所有.jar 字尾的檔案都新增到專案的構建路徑當中
    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:26.+'
    //com.android.support.constraint 是域名。constraint-layout是組名,用於區分同一公司的不同庫。 1.0.2是版本號
    compile 'com.android.support.constraint:constraint-layout:1.0.2'

    //compile project(':helper')  //庫依賴宣告格式,表示依賴了一個叫helper的Library
    // 宣告測試用例庫
    testCompile 'junit:junit:4.12'
}