Android Studio常用的build.gradle 配置

138 篇文章 0 订阅
45 篇文章 0 订阅

//正式环境
def API_RELEASE_HOST = "\"xxxxxxx\""
//测试环境
def API_TEST_HOST = "\"xxxxxxx\""

//开发环境

def API_DEV_HOST = "\"xxxxxxxx\""

//获取当前时间
def getCurrentTime() {
    return new Date().format("yyyyMMddhhmmss", TimeZone.getTimeZone("UTC"))
}

//配置keystore签名  

signingConfigs {
    release {
        storeFile file("xxx.jks")
        storePassword "xxxx"
        keyAlias "xxxxx"
        keyPassword "xxxxx"
    }
    dev {
        storeFile file("xxxxx.jks")
        storePassword "xxxxx"
        keyAlias "xxxxx"
        keyPassword "xxxxxx"
    }
}
buildTypes {
    release {

        //id 根据你自己的需要设置是否可以同时在一个手机上运行多个自己的app。
        applicationIdSuffix ".release"
        //是否输出日志
        buildConfigField "boolean", "LOG_DEBUG", "false"
        //url动态替换,正式url
        buildConfigField "String", "API_HOST", "${API_RELEASE_HOST}"
        // 移除无用的resource文件
        shrinkResources true
        //是否混淆
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    dev {
        applicationIdSuffix ".dev"
        //是否输出日志
        buildConfigField "boolean", "LOG_DEBUG", "true"
        //url动态替换
        buildConfigField "String", "API_HOST", "${API_DEV_HOST}"//API Host
        // 移除无用的resource文件
        shrinkResources true
        //是否混淆
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }

多工程全局配置

先在project的根目录下的build.gradle定义ext全局变量:

ext {
    compileSdkVersion = 27
    buildToolsVersion = '27.0.3'
    minSdkVersion = 16
    targetSdkVersion = 27
    versionCode = 13
    versionName = "v1.13"
}
android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    defaultConfig {
        applicationId "com.xwan.inspect"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [moduleName: project.getName()]
            }
        }


        buildConfigField("String", "API_HOST", "${API_DEV_HOST}")
        flavorDimensions "v1.13"


        ndk {
            //设置支持的SO库架构
            abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
        }

    }

apk输出包重新命名

applicationVariants.all { variant ->
    variant.outputs.all { output ->
        outputFileName = new File("../../apk/${variant.buildType.name}", "demo-${variant.buildType.name}-${variant.versionName}-${variant.productFlavors[0].name}-${getCurrentTime()}.apk")
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值