• Gradle多渠道打包


    关键字

    productFlavors 定义不同的风味
    flavorDimensions 定义产品领域, 定义productFlavors 的必要属性
    manifestPlaceholders 可以替换androidmanifest文件中的标签

    gradle多渠道打包配置在build.gradle里

    关键字 productFlavors flavorDimensions
    productFlavors 定义不同的风味
    flavorDimensions 定义产品领域, 定义productFlavors 的必要属性

    android {	productFlavors {
        A {
            dimension "app"
            manifestPlaceholders = [
                    key_supportsRtl: "true",
                    key_icon       : "@drawable/icon_manual"
            ]
        }	}	}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    android {	flavorDimensions "app","env"	}
    
    
    • 1
    • 2

    manifestPlaceholders替换manifest里的值

    productFlavors {
        A {
            dimension "app"
            manifestPlaceholders = [
                    key_supportsRtl: "true",
                    key_icon       : "@drawable/icon_manual"
            ]
        }	}
       
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    android:icon="${key_icon}"
    
    
    • 1
    • 2

    Gradle修改打包文件名称

    android.applicationVariants.all { variant ->	    variant.outputs.each { output ->	        def outputFile = output.outputFile	        if (outputFile != null && outputFile.name.endsWith('.apk')) {	            def fileName = outputFile.name.replace("之前系统默认名称.apk", "想要替换的名称${defaultConfig.versionName}_${getDate()}.apk")	            output.outputFile = new File(outputFile.parent, fileName)	        }	    }	} 
    
    
    • 1
    • 2

    Gradle 获取时间戳

    调用时使用${getDate()}

    //获取时间戳
    static def getDate() {
        def date = new Date()
        def formattedDate = date.format('MMddHHmm')
        return formattedDate
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    调用	${getDate()}.apk
    
    • 1

    Gradle 获取git提交次数

    获取当前分支的提交次数	def getGitCommitTimes() {
        return 'git rev-list HEAD --first-parent --count'.execute().text.trim().toInteger()
    }	versionName "aaa." + getGitCommitTimes() + "." + new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC"))
    
    • 1
    • 2
    • 3
    def getGitCommitTimes() {
        return 'git rev-list HEAD --first-parent --count'.execute().text.trim().toInteger()
    }
    
    
    • 1
    • 2
    • 3
    • 4

    修改打包路径

    applicationVariants.all { variant ->
        if (variant.buildType.name.equals('release')) {
            variant.outputs.all { output ->
    
                outputFileName = "AppName_" + versionName + ".apk"
            }
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    判断打包的版本

    if(BuildConfig.FLAVOR.equals("external")){//用于判断打包的是哪个版本	}
    
    • 1

    Gradle [解决]:Please correct the above warnings first.

    快速解决方式 ,proguard-rules.pro文件里添加-ignorewarnings
    
    
    • 1
    • 2
  • 相关阅读:
    SpringBoot 使用EasyExcel 导出Excel报表(单元格合并)
    第一篇文章 mybatis 综述
    串口数据接收
    C# 反射为什么慢?深入解析反射性能问题
    idea,web开发中jsp页面中不提示控制层的请求地址
    chatgpt GPT-4V是如何实现语音对话的
    KSF绩效管理
    线程池源码分析
    将el-table数据导出csv各式,纯前端实现
    香港回归20余年,图扑数字孪生港珠澳大桥,超震撼
  • 原文地址:https://blog.csdn.net/Jun_P/article/details/126562883