• 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
  • 相关阅读:
    Oracle 数据库连接不上则么办
    【Rust日报】2022-11-07 使用 Tauri 构建桌面托盘应用
    【matplotlib 实战】--堆叠面积图
    MyBatis(一)--------十分灵活
    Apache Hadoop(一)
    使用 Visual Studio 断点调试 DLL
    英码科技“深元智能应用”入选中国电信原子能力业务,携手共同打造AI智能视频分析应用“超能力”!
    vue2实现可拖拽甘特图(结合element-ui的gantt图)
    CRMEB多商户商城系统阿里云集群部署教程
    HyperBDR云容灾深度解析四:资源组编排简化容灾操作
  • 原文地址:https://blog.csdn.net/Jun_P/article/details/126562883