Android 8:不允许使用Cleartext HTTP流量

dav*_*d.s 782 https android http

我收到了Android 8用户的报告,我的应用(使用后端Feed)没有显示内容.经过调查,我发现在Android 8上发生以下异常:

08-29 12:03:11.246 11285-11285/ E/: [12:03:11.245, main]: Exception: IOException java.io.IOException: Cleartext HTTP traffic to * not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:458)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.deiw.android.generic.tasks.AbstractHttpAsyncTask.doConnection(AbstractHttpAsyncTask.java:207)
at com.deiw.android.generic.tasks.AbstractHttpAsyncTask.extendedDoInBackground(AbstractHttpAsyncTask.java:102)
at com.deiw.android.generic.tasks.AbstractAsyncTask.doInBackground(AbstractAsyncTask.java:88)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Run Code Online (Sandbox Code Playgroud)

(我删除了包名,URL和其他可能的标识符)

在Android 7及更低版本上一切正常,我没有设置android:usesCleartextTrafficManifest(并设置它true没有帮助,无论如何这是默认值),我也没有使用网络安全信息.如果我打电话NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(),它会返回falseAndroid 8,true对于旧版本,使用相同的apk文件.我试图在关于Android O的Google信息上找到一些提及,但没有成功.

Hri*_*dam 1677

根据网络安全配置 -

从Android 9.0(API级别28)开始,默认情况下禁用明文支持.

另外看看 - https://koz.io/android-m-and-the-war-on-cleartext-traffic/

选项1 -

创建文件res/xml/network_security_config.xml -

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">domain.com (to be adjusted)</domain>
    </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml -

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:networkSecurityConfig="@xml/network_security_config"
        ...>
        ...
    </application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

选项2 -

AndroidManifest.xml -

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

另外,正如@ david.s的回答指出的那样android:targetSandboxVersion也是一个问题 -

根据Manifest Docs -

android:targetSandboxVersion

此应用程序要使用的目标沙箱.沙箱版本号越高,安全级别越高.其默认值为1; 您也可以将其设置为2.将此属性设置为2会将应用程序切换到另一个SELinux沙箱.以下限制适用于2级沙箱:

  • usesCleartextTrafficNetwork Security Config中的默认值为false.
  • 不允许共享Uid.

选项3 -

如果你有android:targetSandboxVersion,<manifest>然后减少它1

AndroidManifest.xml -

<?xml version="1.0" encoding="utf-8"?>
<manifest android:targetSandboxVersion="1">
    <uses-permission android:name="android.permission.INTERNET" />
    ...
</manifest>
Run Code Online (Sandbox Code Playgroud)

  • 如果每个开发人员都要添加"android:usesCleartextTraffic ="true"`这个Android安全功能有什么意义呢? (112认同)
  • 这甚至没有提到解决此问题的最佳方法:使用HTTPS。此答案中提到的选项只能是不得已的方法。 (54认同)
  • ClearText HTTP是否意味着他们只使用http网站而不是https? (6认同)
  • @HrishikeshKadam你的答案非常感谢,但似乎在最近发布的P中必须有另一个步骤?请参阅我的问题/sf/ask/3623922641/ (4认同)
  • 将选项1从domain-config更改为base-config为我修复了此问题 (3认同)
  • 这很奇怪,这个问题仍然存在,您的解决方案仍然可以修复它.但是您提供的Google链接已不再提及 (2认同)
  • @林果皞对于Google Play商店而言,最终仅禁止使用该标志的应用程序将很容易 (2认同)
  • 您可以将其设置为仅在调试版本中使用明文流量。请参阅此处:/sf/answers/3761296101/ (2认同)

byO*_*nti 104

在AndroidManifest中我找到了这个参数:

android:networkSecurityConfig="@xml/network_security_config"
Run Code Online (Sandbox Code Playgroud)

和@xml/network_security_config在network_security_config.xml中定义为:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <!--Set application-wide security config using base-config tag.-->
    <base-config cleartextTrafficPermitted="false"/>
</network-security-config>  
Run Code Online (Sandbox Code Playgroud)

只是我改变了cleartextTrafficPermitted为true

  • +1如果您希望在应用程序中使用的所有域中应用它,而不是像其他答案所建议的那样维护子集,则此选项非常有用. (9认同)
  • 当然,禁用 ssl 要求不是一个好的做法,除非这是针对内部应用程序。但即便如此,也不应该被禁用。 (5认同)
  • 完美。更多信息请访问:https://codelabs.developers.google.com/codelabs/android-network-security-config/index.html#3 (2认同)
  • 更改后重新安装应用程序 (2认同)

Tyl*_*ler 66

您可能只想在调试时允许明文,但要保留在生产中拒绝明文的安全性.这对我很有用,因为我针对不支持https的开发服务器测试我的应用程序.以下是如何在生产中强制执行https,但在调试模式下允许明文:

在build.gradle中:

// Put this in your buildtypes debug section:
manifestPlaceholders = [usesCleartextTraffic:"true"]

// Put this in your buildtypes release section
manifestPlaceholders = [usesCleartextTraffic:"false"]
Run Code Online (Sandbox Code Playgroud)

在AndroidManifest.xml中的application标签中

android:usesCleartextTraffic="${usesCleartextTraffic}"
Run Code Online (Sandbox Code Playgroud)


Pab*_*rra 66

我在Android 9中的问题是使用http从这个答案的解决方案导航到域上的webview

<application 
    android:networkSecurityConfig="@xml/network_security_config"
    ...>
Run Code Online (Sandbox Code Playgroud)

和:

RES/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>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

  • 对,最适合20019的答案。 (3认同)
  • 完美地工作!非常感谢! (2认同)

eli*_*eli 57

将您的网址从HTTP更改为HTTPS ;

它工作了!!!

  • 这是怎么回事?如果您的服务器URL不是https,您将获得握手异常 (77认同)
  • 赞成,因为这是正确的做法(在生产环境中)。HTTPS应该是默认值,而不是HTTP。 (18认同)
  • @beetsta您假定您完全控制提供内容的内容。因此,这个答案本质上是幼稚的或轻率的。 (12认同)
  • 答案是对问题一无所知。与小公司的人员不同,有时您并没有为每个临时服务器都配备 SSL。答案就像有人在 Facebook 帖子中纠正语法一样糟糕,这根本不能回答问题,也不能解决问题。 (10认同)
  • @beetstra为什么调试时本地计算机上的HTTPS默认设置?这是如此愚蠢,只是谷歌家长式的另一个例子。幸运的是,泰勒的解决方案可以针对调试模式解决此问题。 (5认同)
  • @MartinPrice,我同意答案太短,并不适用于所有情况。然而,大多数其他答案都不是,假设允许 HTTP 流量是正确的方法。在所有情况下允许所有主机的明文流量完全忽略了谷歌首先改变这一点的原因。对于生产环境,HTTPS 几乎总是正确的方法。正如我在评论中提到的,在调试环境中允许 HTTP 当然不是问题。 (2认同)

小智 32

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">***Your URL(ex: 127.0.0.1)***</domain>
    </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

在上面提供的建议中,我提供的URL为 http://xyz.abc.com/mno/

我把它更改为 xyz.abc.com然后它开始工作了.

  • 域!= URL。“ http”是协议。该协议绝不是域的一部分。 (6认同)

spa*_*rog 20

它可能对某人有用.

我们最近对Android 9有同样的问题,但我们只需要在WebView中显示一些Urls,没什么特别的.因此添加android:usesCleartextTraffic="true"到Manifest工作,但我们不想为此破坏整个应用程序的安全性.因此,固定在更改链接httphttps

  • 如果我只想显示一些URL,我不需要WebView.我只是使用TextView.;)我想你的意思是你显示一些HTML页面.只有在服务器提供SSL时,您的修复才有效.您不能简单地更改链接. (3认同)
  • 当然,这是最好的选择,但由于性能原因或因为资源可能无法在明文HTTP中使用而总是不能总是选择它。 (2认同)

sut*_*her 18

好吧,那是?? 不是?? 成千上万的重复, 将其添加到清单中,但基于此的提示,却给您带来额外的好处(也许还有一些背景信息)。

Android具有src-Directory的一种覆盖功能。

默认情况下,

/ app / src / main

但是您可以添加其他目录来覆盖您的AndroidManifest.xml。下面是它的工作原理:

  • 创建目录/ app / src / debug
  • 在里面创建AndroidManifest.xml

在此文件的内部,您不必将所有规则都放在其中,而只需将您要从/ app / src / main / AndroidManifest.xml中覆盖的规则放进去

这是一个示例,显示请求的CLEARTEXT-Permission的外观:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.yourappname">

    <application
            android:usesCleartextTraffic="true"
            android:name=".MainApplication"
            android:label="@string/app_name"
            android:icon="@mipmap/ic_launcher"
            android:allowBackup="false"
            android:theme="@style/AppTheme">
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

有了这些知识,您现在就可以轻松地将1,2,3作为重载权限的依据,具体取决于您的调试| 主| 释放环境。

这样做的最大好处是……您的生产清单中没有调试资料,并且您可以保持简单易维护的结构

  • 这绝对是正确的解决方案。Android之所以添加这些安全设置是有原因的,因此它们应该保留下来。您的解决方案使我们能够在本地不安全环境中进行测试,而正式产品仍将具有建议的安全设置。谢谢! (2认同)

cre*_*der 16

我已经从已经存在的 android 清单文件中删除了这一行

 android:networkSecurityConfig="@xml/network_security_config" 
Run Code Online (Sandbox Code Playgroud)

并添加

android:usesCleartextTraffic="true"
Run Code Online (Sandbox Code Playgroud)

这在清单中的应用程序标签中

<application
    android:usesCleartextTraffic="true"
    android:allowBackup="true"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    >
Run Code Online (Sandbox Code Playgroud)

那么这个错误明文HTTP流量到overlay.openstreetmap.nl不允许在android 9和10中对我来说消失了。我希望这也适用于android 8如果它有帮助你不要忘记投票谢谢


Eri*_*gel 12

对于React Native项目

它已在RN 0.59上修复。您可以找到从0.58.6到0.59的升级差异。 您可以在不升级RN版本的情况下应用它,请按照以下步骤操作:

创建文件:

Android设备/应用/ src目录/ 调试 /res/xml/react_native_config.xml -

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="false">localhost</domain>
    <domain includeSubdomains="false">10.0.2.2</domain>
    <domain includeSubdomains="false">10.0.3.2</domain>
  </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

Android设备/应用/ src目录/ 调试 /AndroidManifest.xml -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools">

  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

  <application tools:targetApi="28"
      tools:ignore="GoogleAppIndexingWarning" 
      android:networkSecurityConfig="@xml/react_native_config" />
</manifest>
Run Code Online (Sandbox Code Playgroud)

检查接受的答案以了解根本原因。

  • 我使用react-native 0.59.5,并且我遇到相同的问题,我们必须按照您的建议手动设置AndroidManifest.xml。 (2认同)

小智 12

将 ... android:usesCleartextTraffic="true" ... 添加到您的清单文件似乎可以解决问题,但它会对数据完整性构成威胁。

For security reasons I used manifest placeholders with android:usesCleartextTraffic inside the manifest file (like in Option 3 of the accepted answer i.e @Hrishikesh Kadam's response) to only allow cleartext on debug environment.

Inside my build.gradle(:app) file, I added a manifest placeholder like this:

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        debug {
            manifestPlaceholders.cleartextTrafficPermitted ="true"
        }
    }
Run Code Online (Sandbox Code Playgroud)

Note the placeholder name cleartextTrafficPermitted at this line above

            manifestPlaceholders.cleartextTrafficPermitted ="true"
Run Code Online (Sandbox Code Playgroud)

Then in my Android Manifest, I used the same placeholder ...

AndroidManifest.xml -

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="${cleartextTrafficPermitted}"
        ...>
        ...
    </application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

With that, cleartext traffic is only permitted under the debug environment.


小智 12

最简单的解决方案 [Xamarin Form]

安卓版

  1. 转到Android Project,然后单击Properties

在此处输入图片说明

  1. 打开AssemblyInfo.cs并粘贴此代码:

    [assembly: Application(UsesCleartextTraffic =true)]

在此处输入图片说明

对于 iOS

使用NSAppTransportSecurity

在此处输入图片说明

您必须将NSAllowsArbitraryLoads密钥设置为文件中的字典YES下。NSAppTransportSecurityinfo.plist

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>
Run Code Online (Sandbox Code Playgroud)

Plist 配置


Jac*_*cob 12

我建议添加开发和生产网络配置:

添加res/xml/network_security_config_dev.xml

<?xml version="1.0" encoding="utf-8"?>
 <network-security-config>
    <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">10.0.2.2</domain>
 </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

添加res/xml/network_security_config_prod.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="false">
    <domain includeSubdomains="true">yourdomain.com</domain>
  </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

在 Gradle 脚本(在 android studio 中)下,找到build.gradle ( android.app ) 并查找buildTypes发布调试(如果不存在则创建):

buildTypes {

release {
    minifyEnabled false
    manifestPlaceholders.securityConfig = "@xml/network_security_config_prod"
 }

 debug {
    manifestPlaceholders.securityConfig = "@xml/network_security_config_dev"
 }

}
Run Code Online (Sandbox Code Playgroud)

在 AndroidManifest.xml 中使用securityConfig占位符,如下所示(在build.gradle中定义):

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:networkSecurityConfig="${securityConfig}"   <------- here
Run Code Online (Sandbox Code Playgroud)


dav*_*d.s 9

好的,我已经弄明白了.这是由于Manifest参数android:targetSandboxVersion="2",我添加了因为我们也有Instant App版本 - 它应该确保用户从Instant App升级到普通应用程序,他不会通过传输丢失他的数据.但是,模糊的描述表明:

指定此应用程序要使用的目标沙箱.更高的sanbox版本将具有更高的安全级别.

此属性的默认值为1.

它显然也增加了新的安全策略,至少在Android 8上.


Ste*_*ers 7

虽然对我来说有效的答案是@PabloCegarra:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

您可能会收到有关以下内容的安全警告cleartextTrafficPermitted="true"

如果您知道“白名单”的域,您应该混合接受的答案和上面的答案:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="false">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">books.google.com</domain>
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

此代码对我有用,但我的应用程序只需要从 books.google.com 检索数据。这样安全警告就消失了。


Ash*_*hif 6

 cleartext support is disabled by default.Android in 9 and above

 Try This one I hope It will work fine

1 Step:->  add inside android build gradle (Module:App)
            useLibrary 'org.apache.http.legacy'

  android {
               compileSdkVersion 28
              useLibrary 'org.apache.http.legacy'

          }
Run Code Online (Sandbox Code Playgroud)

然后第 2 步:-> 清单添加到清单应用程序标签内

<application
    android:networkSecurityConfig="@xml/network_security_config">//add drawable goto Step 4

   // Step --->3  add to top this line  
     <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

</application>
Run Code Online (Sandbox Code Playgroud)

//第4步-->>创建Drawable>>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>
    </network-security-config>
Run Code Online (Sandbox Code Playgroud)


Sus*_*ver 5

要将这些不同的答案应用于Xamarin.Android,您可以使用类和程序集级别的属性,而无需手动编辑AndroidManifest.xml

当然需要Internet许可(duh ..):

[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
Run Code Online (Sandbox Code Playgroud)

注意:通常,程序集级属性会添加到您的AssemblyInfo.cs文件中,但会添加到作品下方using和上方的任何文件namespace

然后在您的Application子类上(如果需要,请创建一个),可以添加NetworkSecurityConfigResources/xml/ZZZZ.xml文件的引用:

#if DEBUG
[Application(AllowBackup = false, Debuggable = true, NetworkSecurityConfig = "@xml/network_security_config")]
#else
[Application(AllowBackup = true, Debuggable = false, NetworkSecurityConfig = "@xml/network_security_config"))]
#endif
public class App : Application
{
    public App(IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) : base(javaReference, transfer) { }
    public App() { }

    public override void OnCreate()
    {
        base.OnCreate();
    }
}
Run Code Online (Sandbox Code Playgroud)

Resources/xml文件夹中创建一个文件(xml如果需要,请创建文件夹)。

示例xml/network_security_config文件,根据需要进行调整(请参阅其他答案)

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">www.example.com</domain>
          <domain includeSubdomains="true">notsecure.com</domain>
          <domain includeSubdomains="false">xxx.xxx.xxx</domain>
    </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

您还可以在UsesCleartextTraffic上使用参数ApplicationAttribute

#if DEBUG
[Application(AllowBackup = false, Debuggable = true, UsesCleartextTraffic = true)]
#else
[Application(AllowBackup = true, Debuggable = false, UsesCleartextTraffic = true))]
#endif
Run Code Online (Sandbox Code Playgroud)


Nit*_*ith 5

在开发我的应用程序时,我也遇到了相同的“不允许明文 HTTP 流量”错误。我在应用程序中使用 Retrofit2 进行网络调用,并且有两个项目环境(开发和生产)。我的生产域具有带 HTTPS 调用的 SSL 证书,而开发人员没有 https。该配置已添加到构建风格中。但是当我切换到dev时,就会触发这个问题。所以我为此添加了以下解决方案。

我已在清单中添加了明文流量

 android:usesCleartextTraffic="true"
Run Code Online (Sandbox Code Playgroud)

然后我在改造配置类 OKHttp 创建时添加了连接规范。

 .connectionSpecs(CollectionsKt.listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT))
Run Code Online (Sandbox Code Playgroud)

下面给出了完整的OkHttpClient创建

OkHttpClient okHttpClient = new OkHttpClient.Builder()
        .readTimeout(10, TimeUnit.SECONDS)
        .connectTimeout(10, TimeUnit.SECONDS)
        .cache(null)
        .connectionSpecs(CollectionsKt.listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT))
        .addInterceptor(new NetworkInterceptor(context))
        .addInterceptor(createLoggingInterceptor())
        .addInterceptor(createSessionExpiryInterceptor())
        .addInterceptor(createContextHeaderInterceptor())
        .build();
Run Code Online (Sandbox Code Playgroud)


Gvs*_*hil 5

2019 年 12 月更新 ionic - 4.7.1

<manifest xmlns:tools=“http://schemas.android.com/tools”>

<application android:usesCleartextTraffic=“true” tools:targetApi=“28”>
Run Code Online (Sandbox Code Playgroud)

请在android manifest .xml文件中添加以上内容

离子的以前版本

  1. 确保您的config.xmlIonic 项目中有以下内容:

    <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>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 运行 ionic Cordova build android。它在平台下创建 Android 文件夹

  3. 打开 Android Studio 并打开我们项目 project-platforms-android 中的 Android 文件夹。让它停留几分钟,以便它构建 gradle

  4. gradle build完成后,我们得到了一些错误的,包括minSdVersionmanifest.xml。现在我们所做的只是<uses-sdk android:minSdkVersion="19" />manifest.xml.

    确保将其从两个位置移除:

    1. 应用程序 → 清单 → AndroidManifest.xml
    2. CordovaLib → 清单 → AndroidManifest.xml

    现在尝试再次构建gradle,现在它构建成功

  5. 确保在 App → manifest → 的 Application 标签中有以下内容Androidmanifest.xml

    <application
    android:networkSecurityConfig="@xml/network_security_config"  android:usesCleartextTraffic="true" >
    
    Run Code Online (Sandbox Code Playgroud)
  6. 打开network_security_config(app → res → xml →network_security_config.xml)。

    添加以下代码:

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
        <domain-config cleartextTrafficPermitted="true">
            <domain includeSubdomains="true">xxx.yyyy.com</domain>
        </domain-config>
    </network-security-config>
    
    Run Code Online (Sandbox Code Playgroud)

这里 xxx.yyyy.com是您的 HTTP API 的链接。确保在 URL 之前不包含任何 Http。

注意:现在使用 Android Studio (Build -- Build Bundle's/APK -- Build APK) 构建应用程序,现在您可以使用该应用程序并且它在 Android Pie 中运行良好。如果您尝试使用 ionic Cordova build android 构建应用程序,它会覆盖所有这些设置,因此请确保您使用 Android Studio 构建项目。

如果您安装了任何旧版本的应用程序,请卸载它们并尝试一下,否则您将遇到一些错误:

应用未安装