apply plugin: 'com.android.application'
def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
android {
    compileSdkVersion 23

    buildToolsVersion "23.0.3"

   引入第三方so库时需要配置sourceSets

    sourceSets {
        main {                         
        jniLibs.srcDirs = ['libs']                          
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"//编译时内存不足的问题

    }

   配置包名版本等

 defaultConfig {        applicationId "com.packname"        minSdkVersion 14        targetSdkVersion 17        versionCode 1        versionName "1.0.0"        // dex突破65535的限制        multiDexEnabled true        // 默认是umeng的渠道        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "umeng"]    }

 自动签名打包

    signingConfigs {        debug {            keyAlias '。。。'            keyPassword 'passwd'            storePassword 'passwd'            storeFile file('项目keystore')        }        release {            keyAlias '...'            keyPassword 'passwd'            storePassword '1passwd'            storeFile file('项目keystore.jks')        }    }

构建类型,分debug、release

buildTypes {        debug {            // 显示Log            buildConfigField "boolean", "LOG_DEBUG", "true"            buildConfigField "boolean", "API_ENV", "true"           buildConfigField "String", "API_SERVER_URL", "\"http://test...\""           buildConfigField "String", "API_WEB_URL","\"http://test...\""           buildConfigField "String", "API_3G_URL","\"http://www...\""            buildConfigField "String", "IMAGE_TYPE", "\".jpg,.png,.gif\""            versionNameSuffix "-debug"            minifyEnabled false            shrinkResources false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'            signingConfig signingConfigs.debug            debuggable true                    }        release {                     // 不显示Log            buildConfigField "boolean", "LOG_DEBUG", "false"            buildConfigField "boolean", "API_ENV", "false"            buildConfigField "String", "API_SERVER_URL", "\"http://apps...""            buildConfigField "String", "API_3G_URL","\"http://www...""            buildConfigField "String", "API_WEB_URL","\"http://apps...\""            buildConfigField "String", "IMAGE_TYPE", "\".jpg,.png,.gif\""            debuggable false 
            minifyEnabled //使用混淆            zipAlignEnabled true            // 移除无用的resource文件            shrinkResources true            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'            signingConfig signingConfigs.release            applicationVariants.all { variant ->                variant.outputs.each { output ->                    def outputFile = output.outputFile                    if (outputFile != null && outputFile.name.endsWith('.apk')) {                        def fileName = "v${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"                        output.outputFile = new File(outputFile.parent, fileName)                    }                }            }        }    }
   
   

  多渠道打包

productFlavors {       baidu {}        _360 {}        wandoujia {}        yingyongbao{}        yingyonghui{}        jifeng{}        lenovo{}        yidong{}        huawei{}        xiaomi {}
    }
   统一配置
    productFlavors.all {
        flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }
}

第三方库依赖管理

.jar和.aar文件,添加.aar文件还需要配置respositories

repositories {    flatDir {        dirs 'libs'    }}
dependencies {    compile fileTree(include: ['*.jar'], dir: 'libs')    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:23.2.1'    compile 'org.greenrobot:eventbus:3.0.0'    compile 'com.squareup.picasso:picasso:2.5.2'   //.aar文件    compile name: ' 文件name', ext: 'aar'}


更多相关文章

  1. AndroidManifest.xml文件详解(uses-configuration)
  2. Android4.0中修改挂断键(ENDCALL)的默认行为
  3. 禁止状态栏下拉
  4. Android(安卓)intent 传递数组对象序列化
  5. Android(安卓)文件打开方式
  6. android 首页fragment切换
  7. 更换工程的sdk或者google apis
  8. Android腾讯微薄客户端开发十四:首页menu菜单
  9. NPM 和webpack 的基础使用

随机推荐

  1. navicat for mysql 注册码,简简单单,一个搞
  2. MySQL数据库语法-多表查询练习一
  3. MySQL - 更改一行的时间值以匹配同一表
  4. php将图片以二进制形式保存到mysql数据库
  5. 为什么插入忽略递增的auto_increment主键
  6. 解决The'InnoDB'feature is disa
  7. mysql常识以及存储引擎,锁和事务
  8. 05-mysql中的查询(第一章)
  9. Active Record或mysql中的批次计数
  10. Innode表空间碎片优化