Android 如何在network\u security\u config.xml中包含BuildConfig或资源

Android 如何在network\u security\u config.xml中包含BuildConfig或资源,android,localhost,android-build-type,android-network-security-config,Android,Localhost,Android Build Type,Android Network Security Config,为了在Android中对localhost进行http API调用,我需要添加一个网络安全配置来定义我的本地IP地址。当然,每个开发人员的本地IP地址是不同的,所以我把这个值放在gradle.properties中,这样每个人都可以自己重写它。但是,我还没有找到如何在网络安全配置.xml文件中包含该值。我通过在build.gradle中创建buildConfigField或resValue来尝试它,但两者似乎都不起作用。我能做什么 网络安全配置.xml <?xml version="1.0

为了在Android中对localhost进行http API调用,我需要添加一个网络安全配置来定义我的本地IP地址。当然,每个开发人员的本地IP地址是不同的,所以我把这个值放在
gradle.properties
中,这样每个人都可以自己重写它。但是,我还没有找到如何在
网络安全配置.xml
文件中包含该值。我通过在
build.gradle
中创建
buildConfigField
resValue
来尝试它,但两者似乎都不起作用。我能做什么

网络安全配置.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <!-- We are allowed to call localhost on http instead of https:
        https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted -->
        <domain includeSubdomains="true">LOCALHOST</domain>
    </domain-config>
</network-security-config>
格拉德尔酒店

localIpAddress="IP_ADDRESS_HERE"
任何其他解决方案,如如何在
network\u security\u config.xml
中优雅地包含我的本地IP地址,也欢迎使用

localIpAddress="IP_ADDRESS_HERE"