android { compileSdkVersion 21 buildToolsVersion '21.1.2' defaultConfig { minSdkVersion 16 targetSdkVersion 16 Properties props = new Properties() props.load(new FileInputStream("sampleapp/sampleapp.properties")) buildConfigField "String", "key1", props.getProperty("value1") buildConfigField "String", "key2", props.getProperty("value2") } }
根据以上配置,编译后自动生成BuildConfig.java