Ionic6 电容器:添加“cordova-plugin-advanced-http”后,工作室中的应用程序构建开始出现错误,找不到符号 CordovaPluginPathHandler

Nur*_*kar 7 android ionic-framework capacitor cordova-plugin-advanced-http ionic6

请帮助解决这个问题。在命令“ionic Capacitor build android”之后,我能够在 android studio 中构建应用程序。\nAndroid 工作正常,直到我添加了插件 cordova-plugin-advanced-http,错误说明如下:

\n

D:\\temp\\myApp4\\android\\capacitor-cordova-android-plugins\\src\\main\\java\\org\\apache\\cordova\\file\\FileUtils.java:39:错误: 找不到符号\nimport org.apache.cordova.CordovaPluginPathHandler;\n^\n符号:类 CordovaPluginPathHandler\n位置:包 org.apache.cordova

\n
[capacitor] [info] Found 5 Cordova plugins for android:\n[capacitor]        cordova-plugin-advanced-http@3.3.1\n[capacitor]        cordova-plugin-file@7.0.0\n[capacitor]        cordova-plugin-geolocation@4.1.0\n[capacitor]        cordova-plugin-nativestorage@2.3.2\n[capacitor]        cordova-plugin-request-location-accuracy@2.3.0\n[capacitor] \xe2\x88\x9a copy android in 4.44s\n[capacitor] \xe2\x88\x9a Updating Android plugins in 25.69ms\n[capacitor] [info] Found 4 Capacitor plugins for android:\n[capacitor]        @capacitor/app@1.1.1\n[capacitor]        @capacitor/haptics@1.1.4\n[capacitor]        @capacitor/keyboard@1.2.2\n[capacitor]        @capacitor/status-bar@1.0.8\n[capacitor] [info] Found 5 Cordova plugins for android:\n[capacitor]        cordova-plugin-advanced-http@3.3.1\n[capacitor]        cordova-plugin-file@7.0.0\n[capacitor]        cordova-plugin-geolocation@4.1.0\n[capacitor]        cordova-plugin-nativestorage@2.3.2\n[capacitor]        cordova-plugin-request-location-accuracy@2.3.0```\n
Run Code Online (Sandbox Code Playgroud)\n

liu*_*in7 25

您应该升级cordova android 的版本。

对于文件android/variables.gradle

更改cordovaAndroidVersion = '7.0.0'cordovaAndroidVersion = '10.1.2'

同时,您应该将 更改minSdkVersion为 >= 22


ink*_*rot 10

作为临时解决方案,我将 cordova-plugin-file 的版本降级到 6.0.2,它对我有用

  • 最好的解决方案... (2认同)

小智 6

为了确保其有效,请执行以下操作;

  1. 转到文件资源管理器上的此位置,该位置<android\capacitor-cordova-android-plugins\src\main\java\org\apache\cordova\file>包含使您的应用程序正常运行的插件。
  2. 创建一个新文件,将其命名为“ CordovaPluginPathHandler.java
  3. 打开文件,然后将下面的代码粘贴到其中
    /*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at
         http://www.apache.org/licenses/LICENSE-2.0
       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
*/

package org.apache.cordova;

import androidx.webkit.WebViewAssetLoader;

/**
 * Wrapper class for path and handler
 */
public class CordovaPluginPathHandler {

    private final WebViewAssetLoader.PathHandler handler;

    public  CordovaPluginPathHandler(WebViewAssetLoader.PathHandler handler) {
        this.handler = handler;
    }

    public WebViewAssetLoader.PathHandler getPathHandler() {
        return handler;
    }
}
Run Code Online (Sandbox Code Playgroud)
  1. 保存文件,然后去构建应用程序。