我有一个json配置文件,我把它放在res / raw文件夹中。以前我有一个gradle脚本,可以在必要时更新文件内容。
def fetchMeta(buildVariant) {
def flavor = buildVariant.productFlavors.get(0).name
def buildType = buildVariant.buildType.name
def middleMetaFolder = "${buildDir}/intermediates/meta/${flavor}"
def pathToMiddleMeta = "${middleMetaFolder}/latest.json"
def rawFolder = "${buildDir}/intermediates/res/merged/${buildVariant.dirName}/raw/"
def f = new File(pathToMiddleMeta)
boolean doDownload = (!f.exists()) || (f.lastModified() < (System.currentTimeMillis() - 86400000))
// Force on production release
if (doDownload || (flavor == "production" && buildType == "release")) {
new File(middleMetaFolder).mkdirs()
def serverAddress = "https://example.com"
String srcUrl = serverAddress + "/latest.json"
println "Downloading Meta from: " + srcUrl + " to " + pathToMiddleMeta
new URL(srcUrl).withInputStream { i -> f.withOutputStream { it << i } }
} else {
println "Skipping Meta as it exists here: " + pathToMiddleMeta
}
copy {
from pathToMiddleMeta
into rawFolder
}
}
android.applicationVariants.all { variant ->
variant.mergeResources.doLast {
fetchMeta(variant)
}
}
但是至于android gradle插件3.0合并策略已更改且文件具有平面扩展名。如何在更改后更新文件内容?
答案 0 :(得分:0)
有同样的问题,从aapt更新到aapt2
已在Google问题跟踪器中分配了问题 https://issuetracker.google.com/issues/65220623
现在你可以在你的gradle.properties中设置android.enableAapt2 = false