【问题标题】:Ionic network security config离子网络安全配置
【发布时间】:2020-04-22 20:04:00
【问题描述】:

您好,我正在研究离子应用程序。执行此命令ionic cordova build android --prod --release。它确实会生成未签名的 apk 文件,但它也会在 network_security_config 文件中显示错误。

错误 app\src\main\res\xml\network_security_config.xml:4: Error: Missing includeSubdomains attribute [NetworkSecurityConfig] <domain>localhost</domain>

我尝试了多种解决方案,但都不适合我。

参考

How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

How Cordova support Network Security Config introduced by Android 7.0?

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 能否添加network_security_config.xml的内容?您有任何自定义规则吗?
  • @yazantahhan &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;network-security-config&gt; &lt;domain-config cleartextTrafficPermitted="true"&gt; &lt;domain&gt;localhost&lt;/domain&gt; &lt;/domain-config&gt; &lt;/network-security-config&gt; 没有自定义规则

标签: angular ionic-framework ionic3 ionic4


【解决方案1】:

转到resources/android/xml/network_security_config.xml 并将includeSubdomains="true" 添加到域属性。应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
    </domain-config>
</network-security-config>

【讨论】:

  • yazantahhan 感谢您的回答,它解决了 includeSubdomains 属性的问题,但在构建时它确实显示了一些其他错误。在此错误不存在之前 错误 Explanation for issues of type "MissingDefaultResource": If a resource is only defined in folders with qualifiers like -land or -en, and there is no default declaration in the base folder (layout or values etc), then the app will crash if that resource is accessed on a device where the device is in a configuration missing the given qualifier. 期待收到您的来信。
  • 你可以尝试输入ionic cordova resources然后尝试构建
  • 如果这不起作用,请尝试删除平台并重新添加它
  • 首先我确实删除了平台,然后构建了cordova资源,然后当我运行这个命令ionic cordova build android --prod --release它确实在android平台上生成了config.xml文件,对吗?,有链接配置文件中的资源出错了。
  • 我之前没有收到这个错误。他在抱怨哪个文件?是一些启动画面图像吗?也许这个线程是相关的github.com/apache/cordova-android/issues/689
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-23
  • 1970-01-01
  • 1970-01-01
  • 2019-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多