问题由来
在做项目的时候,需要接入听云监测系统,因为我们的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