Gradle 的配置

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)
                    }
                }
            }
        }
    }
 
</pre><pre>

  多渠道打包

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'

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值