我有两个环境,我的项目一个Prod另一个是Staging.因此,每当我必须构建任何环境时,我都必须更改多个键,例如地图键,标签名称和清单中的其他内容.所以我搜索并找出一些解决方案,而manifestPlaceholders就是其中之一.
现在我想做的是在manifestPlaceholders中分配多个值.那么我可以在其中放置多个值,是的,然后如何在其中放置多个值.这是manifestPlaceholders的代码
buildTypes { debug { manifestPlaceholders = [ google_map_key:"your_dev_key"] } release { manifestPlaceholders = [ google_map_key:"prod_key"] } }
解决方法
我通过添加多个manifestPlaceholders值来解决我的问题,如下面的代码.将此添加到我的模块build.gradle中.
productFlavors { staging { applicationId "xxxxxxxxxxx" manifestPlaceholders = [ google_map_key:"xxxxxxxxxx",app_label_name:"xxxxxxx"] buildConfigField 'String','BASE_URL','"xxxxxxxxxx"' } prod { applicationId "xxxxxxxxxxx" manifestPlaceholders = [ google_map_key:"xxxxxxxxxx",'"xxxxxxxxxx"' } }
编辑:
您也可以使用resValue作为Emanuel Moecklin在评论中提出的建议.
productFlavors { staging { applicationId "xxxxxxxxxxx" manifestPlaceholders = [ google_map_key:"xxxxxxxxxx",app_label_name:"xxxxxxx"] buildConfigField 'String','"xxxxxxxxxx"' resValue "string","base_url","xxxxxxxxxx" } prod { applicationId "xxxxxxxxxxx" manifestPlaceholders = [ google_map_key:"xxxxxxxxxx","xxxxxxxxxx" } }