access Properties file located in app folder in src file in android -


i want access property file module root, failed find suitable example access property file many tells how access asset in android. app structure follows,

├── app │   ├── key.properties  <--it property file, contains app keys,to used in app  │   └── src             <-- here want access key.properties access keys  ├── build.gradle ├── gradle ├── gradlew ├── gradlew.bat ├── settings.gradle └── local.properties 

mike m correct in should use gitignore hide file git won't pushed on repository.

to expand bit on this, here's solution have gradle load properties during build, , make them available app via buildconfig.

1/ app/build.gradle

before android { ... } plugin, add:

properties props = new properties() try {     props.load(file('keys.properties').newdatainputstream()) } catch (exception ex) {     throw new gradleexception("missing keys.properties file."); } 

2/ app/build.gradle

in buildtypes config, add

buildtypes {     debug {         buildconfigfield "string", "key_my_prop", "\"${props.getproperty("mypropkey")}\""     }     release {         buildconfigfield "string", "key_my_prop", "\"${props.getproperty("mypropkey")}\""         minifyenabled false         proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'     } } 

3/ class in app

your key accessible buildconfig.key_my_prop


Comments