Gradle 配置多渠道打包,替换桌面icon, app_name , 不同apk替换不同资源文件

Gradle 配置多渠道打包,替换桌面icon, app_name , 不同apk替换不同资源文件

很久没有写博客了,因为新入职公司很忙, 每天任务很多, 根本没时间整理,最近因为公司项目需要不同版本出不同版本的apk ,很多资源文件和桌面icon name也可能需要替换,所以去研究了一下gradle 配置,打包apk 这些文件自动替换, 这样就可以方便很多了.:查找了很多资料,都或多或少有些缺少,都没达到要求,最终自己整理一下, 以后就可以查找自己的博客,方便日后工作.

  1. Manifest 中; application配置
android:appComponentFactory="app"
android:icon="${app_icon}"
android:label="${app_label}"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning,HardcodedDebugMode"
tools:replace="android:name,android:icon,android:label,android:theme,android:appComponentFactory"
  1. gradle 配置
defaultConfig {
flavorDimensions "App"
}

buildTypes{	
	release{
	// 批量打包
	applicationVariants.all { variant ->
  	variant.outputs.all {
        outputFileName = "${variant.productFlavors[0].name}_v${defaultConfig.versionName}_${releaseTime()}.apk"
    }
}
	}

}
// 多渠道/多环境 的不同配置
    productFlavors {
        master {
//            applicationId "com.xxx.xxxxx" // 配置不同appid
            // 动态添加 string.xml 字段;注意,这里是添加,在 string.xml 不能有这个字段,会重名!!!
            //将colors 中home_back 删除,
//            resValue "color", "home_back", "#0D1B35"
            // 修改 AndroidManifest.xml 里渠道变量
            manifestPlaceholders = [app_icon : "@mipmap/logo_main",
                                    app_label: "@string/app_name"]
            dimension "App"
        }
        normal {
//            applicationId "com.xxx.xxxxxx"
//            resValue "color", "home_back", "#0D1B35"  // string 中不能有home_back 这个字段,否则报错
            manifestPlaceholders = [app_icon : "@mipmap/logo",
                                    app_label: "@string/app_name"]
            dimension "App"
        }

    }
    // 配置不同apk的获取资源目, 需要配置一下
   
    sourceSets{
        master.res.srcDirs=['src/main/res'] //指定编译的目录
        normal.res.srcDirs=['src/main/res-normal']

    }

在这里插入图片描述

这样就可以替换了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一声紫金,一生紫金

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值