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库架构
            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会关闭lint分析进度
        quiet true
        // 如果为true,则在发现错误时停止gradle构建
        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]
}
 
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,637评论 25 708
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,001评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,974评论 6 342
  • 1.介绍 如果你正在查阅build.gradle文件的所有可选项,请点击这里进行查阅:DSL参考 1.1新构建系统...
    Chuckiefan阅读 12,190评论 8 72
  • 克劳塞维茨在《战争论》中说: 战略追求的,只能是可能的结果,而不是一定能得到的结果,那还需要命运和运气。
    欧阳司空阅读 222评论 0 0