Gradle 使用小技巧

apply plugin: 'com.android.application'
apply plugin: 'com.antfortune.freeline'
apply plugin: 'maven'

android {
    signingConfigs {
        config {
            storeFile file('')
            storePassword ''
            keyAlias ''
            keyPassword ''
        }
    }
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    dexOptions {
        incremental true
        javaMaxHeapSize "4g" //specify the heap size for the dex process
        preDexLibraries = true //delete the already predexed libraries 
    }
    defaultConfig {
        ndk {
            //設置支持的SO庫架構(gòu)
            abiFilters 'armeabi', 'armeabi-v7a', 'x86'//, 'armeabi-v7a', 'x86_64', 'arm64-v8a'
        }
        applicationId ""
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 11
        versionName "2.3.0"
        multiDexEnabled true
        signingConfig signingConfigs.config
    }


    lintOptions {
        // 設置為true會關(guān)閉lint分析進度
        quiet true
        // 如果為true,則在發(fā)現(xiàn)錯誤時停止gradle構(gòu)建
        abortOnError false
        // 如果為true,則只報告錯誤
        ignoreWarnings true
    }

    buildTypes {//兩種類型,這里可以使用不同的名字,然后在src下建立相同的名字,在打包的時候會去找相同名字的文件,如果找不到,就去找main默認文件件,可以作為替換資源文件時打包使用。
        release {
            zipAlignEnabled true
            shrinkResources true//移除無用的resource文件
            minifyEnabled false//是否開啟混淆
            shrinkResources    //去除無用的resource文件
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'//加載混淆配置文件
            debuggable false
            signingConfig signingConfigs.config
        }
        debug {
            manifestPlaceholders = [
                    UMENG_CHANNEL_VALUE: ,
                    QQ_APP_ID :"",//QQappid
                    QQ_APP_ID_VALUE :"",//
                    SHARE_SDK_VALUE :"",//sharesdk
                    TD_APP_ID_VALUE    : "",//talkingdata

                    GETUI_APP_ID       : "",
                    GETUI_APP_KEY      : "",
                    GETUI_APP_SECRET   : "",
                    JPUSH_KEY          : "",
                    HUAWEI_KEY         : "",
                    BAIDU_ID           : "",
                    BAIDU_KEY          : "",
                    XIAOMI_ID          : "",
                    XIAOMI_KEY         : "",
                    PACKAGE_NAME       : ""]
            minifyEnabled false
            debuggable true
            signingConfig signingConfigs.config
        }
    }
//修改打包名字
//    applicationVariants.all { variant -> 
//        variant.outputs.each { output ->
//            def outputFile = output.outputFile
//            def fileName = "xuexitoutiao_v${defaultConfig.versionName}_${releaseTime()}.apk"
//            output.outputFile = new File(outputFile.parent, fileName)
//        }
//    }


    freeline {
        hack true
        productFlavor ""
    }


    productFlavors {


        xxtt {
            applicationId ""
            manifestPlaceholders = [
                    UMENG_CHANNEL_VALUE: name,
                    QQ_APP_ID :"",//QQappid
                    QQ_APP_ID_VALUE :"",//
                    SHARE_SDK_VALUE :"",//sharesdk
                    TD_APP_ID_VALUE    : "",//talkingdata

                    GETUI_APP_ID       : "",
                    GETUI_APP_KEY      : "",
                    GETUI_APP_SECRET   : "",
                    JPUSH_KEY          : "",
                    HUAWEI_KEY         : "",
                    BAIDU_ID           : "",
                    BAIDU_KEY          : "",
                    XIAOMI_ID          : "",
                    XIAOMI_KEY         : "",
                    PACKAGE_NAME       : ""]
        }
    }

}
def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile project(':my-image-browser')
    compile project(':')
}
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: uri('')) {
                authentication(userName: '', password: '')
            }
            snapshotRepository(url: uri('')) {
                authentication(userName: '', password: '')
            }
        }
    }
}

在整個項目中的build.gradle中 加入


def supportVersion = "23.2.1"

ext{
    supportV4 = "com.android.support:support-v4:${supportVersion}"
    appCompat = "com.android.support:appcompat-v7:${supportVersion}"
    cardView  = "com.android.support:cardview-v7:${supportVersion}"
    designCompat  = "com.android.support:design:${supportVersion}"
}

模塊中可以使用

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile rootProject.ext.appCompat
    compile rootProject.ext.cardView
    compile rootProject.ext.designCompat
    compile project(':coverflow')
}

3.多渠道打包

productFlavors {
 
wandoujia {}
baidu {}
c360 {}
uc {}
 
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
 
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,094評論 25 709
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評論 19 139
  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,275評論 6 342
  • 1.介紹 如果你正在查閱build.gradle文件的所有可選項,請點擊這里進行查閱:DSL參考 1.1新構(gòu)建系統(tǒng)...
    Chuckiefan閱讀 12,365評論 8 72
  • 克勞塞維茨在《戰(zhàn)爭論》中說: 戰(zhàn)略追求的,只能是可能的結(jié)果,而不是一定能得到的結(jié)果,那還需要命運和運氣。
    歐陽司空閱讀 241評論 0 0

友情鏈接更多精彩內(nèi)容