Android 中的离子 5/电容器 ERR_CLEARTEXT_NOT_PERMITTED [英] Ionic 5/Capacitor ERR_CLEARTEXT_NOT_PERMITTED in Android

查看:38
本文介绍了Android 中的离子 5/电容器 ERR_CLEARTEXT_NOT_PERMITTED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Capacitor 来构建 Ionic 应用程序.这些是为了在 Android Studio 中打开 android 应用而运行的以下命令.

I'm using Capacitor for building the Ionic app. These are the following commands run in order to open the android app in Android Studio.

npx cap add android
ionic build
npx cap copy
npx cap open android

在 Android Studio 中,我运行构建并单击运行,然后我在我的设备中看到错误 net::ERR_CLEARTEXT_NOT_PERMITTED.我看到过各种帖子都有相同的错误,但这些帖子都是 Cordova 构建的.就我而言,我没有使用 Cordova 来准备 android 应用.

In Android Studio, I ran the build and click on Run after which I see the error net::ERR_CLEARTEXT_NOT_PERMITTED in my device. I have seen various posts having the same error but those are with Cordova build. In my case, I'm not using Cordova for preparing the android app.

这是我的 Ionic 应用程序的一些摘录.

Here are few excerpts from my Ionic App.

capacitor.config.json文件

{
  "appId": "com.abc",
  "appName": "abc",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "www",
  "cordova": {
    "preferences": {
      "ScrollEnabled": "false",
      "android-minSdkVersion": "19",
      "BackupWebStorage": "none",
      "SplashMaintainAspectRatio": "true",
      "FadeSplashScreenDuration": "0",
      "SplashShowOnlyFirstTime": "false",
      "SplashScreen": "none",
      "SplashScreenDelay": "0"
    }
  },
  "server": {
    "url": "http://192.168.1.208:8100"
  }
}

我在Android Studio的LogCat中也看到了这个错误

I also see this error in LogCat of Android Studio

W/cr_AwContents: Application attempted to call on a destroyed WebView
    java.lang.Throwable
        at org.chromium.android_webview.AwContents.a(PG:127)
        at org.chromium.android_webview.AwContents.a(PG:209)
        at com.android.webview.chromium.WebViewChromium.evaluateJavaScript(PG:8)
        at android.webkit.WebView.evaluateJavascript(WebView.java:1113)
        at com.getcapacitor.cordova.MockCordovaWebViewImpl$1.run(MockCordovaWebViewImpl.java:203)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6923)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)

推荐答案

这篇帖子帮助我找到了我的解决方案问题.

This post helped me find the solution to my problem.

我删除了 capacitor.config.json 文件中的字段 server 以使其工作.

I removed the field server in the capacitor.config.json file to make it work.

"server": {
    "url": "http://localhost:8100"
}

现在我的 capacitor.config.json 看起来像

Now my capacitor.config.json looks like

{
  "appId": "com.abc",
  "appName": "abc",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "www",
  "cordova": {
    "preferences": {
      "ScrollEnabled": "false",
      "android-minSdkVersion": "19",
      "BackupWebStorage": "none",
      "SplashMaintainAspectRatio": "true",
      "FadeSplashScreenDuration": "0",
      "SplashShowOnlyFirstTime": "false",
      "SplashScreen": "none",
      "SplashScreenDelay": "0"
    }
  }
}

这篇关于Android 中的离子 5/电容器 ERR_CLEARTEXT_NOT_PERMITTED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆