gradle相关配置

apply plugin: 'com.android.application'

class StringExtension {
    String string

    StringExtension(String string) { this.string = string }

    public void setString(String string) { this.string = string }

    public String getString() { return string }
}
android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    defaultConfig {
        applicationId "com.test.gradle"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 17
        versionName "1.8.0"
        resConfigs "zh"
        multiDexEnabled true
    }

    buildTypes {
        debug {
            shrinkResources true  // 移除无用的resource文件, 有代码动态调用资源文件的不能用,否则会找不到相关资源的
            buildConfigField "boolean", "ISDEBUG", "true"  //通过BuildConfig.ISDEBUG 设置是否为debug模式,控制log输出
            manifestPlaceholders = [BAIDU_KEY: "Rwdyl82FEoMNGCo2ZaGq7c", CHANNEL_NAME: "debug", UM_KEY: "567a6059e55ac54b003059"] //debug模式采用debug的key
        }

        release {
            minifyEnabled true  //打开混淆
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            buildConfigField "boolean", "ISDEBUG", "false"
            manifestPlaceholders = [BAIDU_KEY: "U5jb5t7yipsOZOcAd1MTja"]

		//根据不同渠道重命名生成的文件
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        def fileName = defaultConfig.versionName.replace(".", "_") + "_" + variant.productFlavors[0].channel.string + '.apk'
                        output.outputFile = new File(outputFile.parent, fileName)
                    }
                }
            }
        }
    }

//所有的x86/x86_64/armeabi-v7a/arm64-v8a设备都支持armeabi架构的.so文件,因此似乎移除其他ABIs的.so文件是一个减少APK大小的好技巧。

//但事实上并不是:这不只影响到函数库的性能和兼容性。如x86设备能够很好的运行ARM类型函数库,但并不保证100%不发生crash

    splits {
    	abi {
enable true reset() //重置ABI列表为只包含一个空字符串(这可以实现,在与include一起使用来可以表示要使用哪一个ABI,而不是要忽略哪一些ABI) include 'armeabi' //为了减小体积,只打包了armeabi的库 } } //渠道配置 productFlavors { whenObjectAdded { flavor -> //为了输出中文渠道名,自定义了个变量 flavor.extensions.create("channel", StringExtension, '') } _test99 { channel.string = "开发" buildConfigField "int", "SERVER_INDEX", "2" manifestPlaceholders = [CHANNEL_NAME: "99", UM_KEY: "567a6059e0f5554b003059"] } _test { channel.string = "测试" buildConfigField "int", "SERVER_INDEX", "0" manifestPlaceholders = [CHANNEL_NAME: "测试", UM_KEY: "567a6059e55ac54b003059"] } } lintOptions { checkReleaseBuilds false abortOnError false } dexOptions { incremental true javaMaxHeapSize "4g" }}dependencies { compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值