Vla*_*nko 6 android preprocessor gradle
我有一个项目有多个本地化。
现在我必须strings.xml
为不同的 buildType替换所有文件中的某个单词。例如,假设我有这个:
<string>My name is Bill</string>
<string>Bill is on duty today</string>
Run Code Online (Sandbox Code Playgroud)
在另一个 buildType 中,我需要
<string>My name is Will</string>
<string>Will is on duty today</string>
Run Code Online (Sandbox Code Playgroud)
我该怎么做(可能通过 Gradle)?
好的,找到了正确的解决方案,这不是解决方法:对于所需的buildType
添加以下内容
applicationVariants.all { variant ->
variant.mergeResources.doLast {
def dir = new File("${buildDir}/intermediates/res/merged/${variant.dirName}") //iterating through resources, prepared for including to APK (merged resources)
println("Resources dir " + dir)
dir.eachFileRecurse { file ->
if(file.name.endsWith(".xml")) { //processing only files, which names and with .xml
String content = file.getText('UTF-8')
if(content != null && content.contains("Bill")) {
println("Replacing name in " + file)
content = content.replace("Bill", "Will") //replacing all Bill words with Will word in files
file.write(content, 'UTF-8')
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3133 次 |
最近记录: |