自定义gradle插件实现不同版本app的听云配置文件

问题由来

在做项目的时候,需要接入听云监测系统,因为我们的app分为 debug->preRelease->release 版本。这样的话,需要再在三个不同的版本平台同时接入。
不过听云的接入有一点比较坑的地方是需要配置tingyun.properties文件再app目录,
每次手动去新建肯定是不合适的,自然而然的就想到了gradle打包脚本,不过一开始是写在gradle.properties文件里的,具体代码如下

File TingyunProperties = new File("${project.projectDir.absolutePath}/tingyun.properties")
            TingyunProperties.createNewFile()
        //gradle build package name
        android.applicationVariants.all {
    variant ->
        variant.productFlavors.each {
    flavor ->
            def variantSuffix = variant.name.capitalize()
            def generateResourcesTask = project.tasks.getByName("compile${variantSuffix}Sources")
            def generatePropertiesTask = task("TingyunGenerateProperties${variantSuffix}") {
   
                doLast {
   
                    Properties properties = new Properties()
                    properties.load(TingyunProperties.newDataInputStream())
                    properties.setProperty("authKey", "")
                    properties.setProperty("appKey", flavor.manifestPlaceholders.tingyunAppToken)
                    properties.setProperty("mapping_file_auto_upload", "true")
                    properties.store
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值