Ionic 我在我的移动的上运行时得到ERR_CLEARTEXT_NOT_PERMITTED,但它在webview和模拟器上运行良好

flvlnr44  于 5个月前  发布在  Ionic
关注(0)|答案(4)|浏览(77)

我在项目上使用Laravel Echo Ionic。在移动的设备上运行时,我得到了ERR_CLEARTEXT_NOT_PERMITTED错误,但它在Webview和模拟器上运行良好。
我试着加上

<uses-permission android:name=“android.permission.INTERNET” />
<uses-permission android:name=“android.permission.ACCESS_NETWORK_STATE” />
<uses-permission android:name=“android.permission.ACCESS_WIFI_STATE” />

字符串
AndroidManifest.xml,但它不工作。
我试着加上

<access origin=“*”/>
<allow-intent href=“*” />
<allow-navigation href=“*” />


上。
最后,我尝试使用

<edit-config file=“app/src/main/AndroidManifest.xml” mode=“merge” target=“/manifest/application”>
   <application android:usesCleartextTraffic=“true” />
</edit-config>


但对我来说并不管用
有什么办法解决这个问题吗?

ryoqjall

ryoqjall1#

它最近刚刚发生在我身上,如果你试图从你的设备连接到任何外部服务器(因为你提到了laravel echo,那么我假设你正在尝试连接到一个IP),那么也许你可以试试这个。
如果你注意到了,位于“resources”文件夹中的network_security_soft.xml将被复制到你的android“app”文件夹中。

...

<platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:networkSecurityConfig="@xml/network_security_config" />
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
        <allow-intent href="market:*" />
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
...
</platform>
...

字符串
也许可以尝试将位于resources/android/xml/network_security_config.xml中的network_security_config.xml文件修改为:

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


希望这对你有帮助。

yhuiod9q

yhuiod9q2#

network_security_config.xml

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

字符串
只输入IP地址(没有http://或https://).这对我来说是工作

b1uwtaje

b1uwtaje3#

要在移动的设备上运行它,您需要在项目中进行一些配置,按照下面的文件路径,您将获得三种可能的解决方案
resources/android/xml/network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
     <base-config cleartextTrafficPermitted="true">
       <trust-anchors>
           <certificates src="system" />
       </trust-anchors>
   </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain>localhost</domain>
        <domain includeSubdomains="true">YOUR DOMAIN/IP</domain>
    </domain-config>
</network-security-config>

字符串
config.xml

<access origin="*" />
<platform name="android">
        <preference name="Scheme" value="http" />
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:networkSecurityConfig="@xml/network_security_config" />
            <application android:usesCleartextTraffic="true" />
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
  </platform>


platforms/android/app/src/main/AndroidManifest.xml

<application android:usesCleartextTraffic="true">

0s7z1bwu

0s7z1bwu4#

我的network_security_login.xml文件中的一些变化,你可以尝试。这是为我工作。添加您的IP地址

<?xml version="1.0" encoding="utf-8"?><network-security-config>
<domain-config cleartextTrafficPermitted="true">
    <domain>localhost</domain>
      <domain>http://192.168.0.51:8082/hbpms"</domain>
</domain-config>

字符串

相关问题