app/build.gradle配置解讀

只關注有註釋的部分就可以

apply plugin: 'com.android.application'
//apply plugin: 'me.tatarka.retrolambda' // 引用簡化語法lambda
println "username= ${rootProject.ext.username}"

def androidId = rootProject.ext.androidId
def appId = rootProject.ext.appId
def support = rootProject.ext.dependencies
def url = rootProject.ext.url

android {
    compileSdkVersion androidId.compileSdkVersion
    defaultConfig {
        applicationId appId.app
        minSdkVersion androidId.minSdkVersion
        targetSdkVersion androidId.targetSdkVersion
        versionCode androidId.versionCode
        versionName androidId.versionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    // 簽名配置信息必須在buildTypes之前
    signingConfigs {
        debug {
            storeFile file('C:/Users/chq/.android/debug.keystore')
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
        release {
            // 簽名證書文件
            storeFile file('C:/Users/chq/.android/debug.keystore')
            // 簽名證書類型
            storeType "netease"
            // 簽名密碼
            storePassword "android"
            // 別名
            keyAlias "androiddebugkey"
            // 祕鑰的密碼
            keyPassword "android"
            // 是否開啓V2打包
            v2SigningEnabled true
        }
    }
    buildTypes {
        debug {
            buildConfigField("String", "debugUrl", "\"${url.debug}\"")
            signingConfig signingConfigs.debug
        }
        release {
            minifyEnabled false
            buildConfigField("String", "releaseUrl", "\"${url.release}\"")
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//            signingConfig signingConfigs.release
        }
    }

    adbOptions {
        //配置操作超時時間,單位毫秒
        timeOutInMs = 5*1000
        //adb install 命令的選項配置
        installOptions '-r', '-s'
    }
    // 對dx 操作的配置,接收一個DexOptions類型的閉包,配置由DexOptions 提供
    dexOptions {
        // 配置執行dx 命令是爲其分配的最大堆內存
        javaMaxHeapSize "4g"
        // 配置是否預執行 dex libraries 工程,開啓後會提高增量構建速度,不過會影響clean構建的速度,默認true
        preDexLibraries = false
        // 配置是否開啓 jumbo 模式,代碼方法是超過65535 需要強制開啓才能構建成功
        jumboMode true
        // 配置Gradle 運行dx 命令時使用的線程數量
        threadCount 8
        // 配置multidex參數
        aditionalParameters = [
                '--multi-dex', // 多dex分包
                '--set-max-idx-number=50000', // 每個包內方法數上限
                // '--main-dex-list='+'/multidex-config.txt',//打包到主classes.dex 的文件列表
                '--minimal-main-dex'
        ]
    }
    // 執行gradle lint 命令即可運行lint檢查,默認生成的報告在outputs/lint-results.html中
    lintOptions {
        // 遇到lint 檢查錯誤會終止構建,一般設置爲 false
        abortOnError false
        // 將警告當做錯誤來處理 (老版本:warningAsErros)
        warningsAsErrors false
        // 檢查新 API
        check 'NewApi'
    }
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
    //省略
    configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:26.1.0'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
//    implementation support.appcompat
//    implementation support.constraint
    support.each {k,v -> implementation v}

    implementation 'com.android.support:design:26.1.0'

    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.9' //必須
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' //必須
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.jakewharton:butterknife:8.4.0'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.squareup.okio:okio:1.14.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章