如何针对不同的构建变体具有不同的network-security-config? [英] How to have different network-security-config for different build variants?

查看:83
本文介绍了如何针对不同的构建变体具有不同的network-security-config?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想信任一个构建变量中的证书。

I would like to trust certificate only in one build-variant. How to make it?

推荐答案

为变体创建源。在该源集中创建一个 res / xml / 目录,并将网络安全配置XML放在其中。根据需要在该源集中创建其他内容(例如, res / raw / 和您的证书)。在该源集中,创建一个 AndroidManifest.xml 文件,其中一个< application> 元素仅包含 android:networkSecurityConfig 属性,仅此而已。

Create a source for the variant. Create a res/xml/ directory in that source set, and put your network security configuration XML in there. Create other stuff in that source set as needed (e.g., res/raw/ and your certificate). In that source set, create an AndroidManifest.xml file, with an <application> element that just has the android:networkSecurityConfig attribute and nothing else.

您应该做得到。

此变体的版本将包括您的源集,并合并到 android:networkSecurityConfig 属性中,并利用与其相关的资源。针对其他变体的版本将忽略此源集,从而使您无法进行网络安全配置。

Builds for this variant will include your source set, merge in the android:networkSecurityConfig attribute, and leverage the resources tied to it. Builds for other variants will ignore this source set, leaving you without a network security configuration.

这篇关于如何针对不同的构建变体具有不同的network-security-config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆