Ionic Android project can not be packaged in the HTTP communication problems 9 or later

Ionic Android project can not be packaged in the HTTP communication problems 9 or later

the reason

Use http request request background information in the Ionic development, when the browser test was very successful! But le, there will be some flaws in the real test of time, what le flaw is found Android9 real machine and over time the test will always display request failed! In fact, because cross-domain problem, the browser debugging, you can send a request to our background using a proxy; but cross-domain does not exist in the real machine debugging, so the agency removed, but they make life difficult for the normal http request. In other words, Android9 and above Android version need to use https communication, does not support the http traffic, but there is a way!

Solution

In platforms \ android \ app \ src \ main \ res \ xml \ network_security_config.xml file code into the form below:

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

Here Insert Picture Description

Open the android manifest.xml file, add android in the application tab: networkSecurityConfig = "@ xml / network_security_config"

android:networkSecurityConfig="@xml/network_security_config"

Because sometimes remove off the platform to re-add, so every time to reconfigure network_security_config.xml is especially troublesome, but later found ionic default has already proposed this to the configuration in myApp / config.xml where in the ionic start myApp blank:

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

Here Insert Picture Description

Then it! Ha ha ha! Perfect ~

Published 143 original articles · won praise 166 · views 70000 +

Guess you like

Origin blog.csdn.net/weixin_42776111/article/details/104960505