在构建时下载 Android 个字符串资源

Download Android string resources at build time

我在开发一个应用程序,其中我们在线提供 strings.xml 文件的不同翻译以众包翻译。翻译工具提供了一个 API 用于访问每个 URL 的 xml 个文件。

例如:https://localise.biz/api/export/locale/en.xml?format=android&key=7qUo-LUKd4VIHSwRYB5005T7QQbaFCGw

是否可以在 gradle 构建开始时下载并包含这些文件?

期待您的回答!

IamAshKS 为我提供了答案。我是这样解决的:

task downloadTranslations {
   group 'pre-build tasks'
   description 'Downloads all translation files when building the app.'

   ext.apiKey = '7qUo-LUKd4VIHSwRYB5005T7QQbaFCGw'

   //English
   doLast {
      def f = new File("${project.projectDir}/src/main/res/values/strings.xml")
      new URL("https://localise.biz/api/export/locale/en.xml?format=android&key=${apiKey}").withInputStream{ i -> f.withOutputStream{ it << i }}
   }
}

非常感谢您的帮助!现在,我只需要在实际构建之前 运行 得到它。