Android开发的时候,我们平时在gradle.properties文件中写一个参数a,然后在build.gradle中获取直接就是"${a}"这样的形式就可以。但是如果我们需要配置其他的大量的参数呢?
我重新创建了一个文件apkrelative.properties,其中有很多参数需要获取,这个时候怎么办呢?
image
这里需要知道,Androidstudio运行的时候现运行的是那个文件,整理项目来说settings.gradle是最先运行的gradle文件。我们在这里面去获取apkrelative.properties配置。
image
为了防止图片看不见,我还是贴代码。
在settings.gradle中定义一个方法:~~~groovy
def initProperties(){
String fileName = "apkrelative.properties"
Properties properties = new Properties()
File proFile = new File(rootDir.getAbsolutePath(), fileName)
//确保中文正常显示
properties.load(proFile.newReader("utf-8"))</