我的应用程序(调试和发布)有一些 google map api key 。
为了使用 API,我必须像这样在 list 中添加 key :
<meta-data
android:name="com.google.android.maps.API_KEY"
android:value="apikey" />
出于安全原因,我不想将原始 key 留在 list 中。
解决此问题的最佳解决方法或推荐的方法是什么?
我目前必须在我的构建配置中添加变量,这些变量具有用于调试和发布的键。
最佳答案
为“应用程序”执行“gradle.build”中的键。
buildTypes {
release {
buildConfigField "String", "DBREST", "\"DB REST RELEASE\""
resValue "string", "maps_api_key", configMapApiR
}
debug {
buildConfigField "String", "DBREST", "\"DB REST RELEASE\""
resValue "string", "maps_api_key", configMapApiD
}
}
将键值作为标准 K-V 对插入“gradle.properties”中
configMapApiR=$yourKey
configMapApiD=
在代码中使用android资源值...
getString(R.string.maps_api_key));
关于android - 将构建配置值添加到 list 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27422005/