简体   繁体   中英

Android Native - Where to put secret, endpoints, keys?

AFAIK there are 2 possibilities:

1. local.properties

.
├── app
│   ├── build.gradle
│   └── src
├── build.gradle
├── gradle
├── gradlew
├── gradlew.bat
├── settings.gradle
└── local.properties

with

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def sdkDir = properties.getProperty('sdk.dir')
def ndkDir = properties.getProperty('ndk.dir')

2. src > build.gradle > defaultConfig || other configs

defaultConfig {
    ...
    buildConfigField "String", "API_KEY", "\"${System.env.API_KEY}\""
}
println(BuildConfig.API_KEY)

What method should I use?

This is the Good Answer for your Question- Link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM