Ionic Build Android 命令在尝试添加 ngCordova 日历插件后失败并出现异常

Ionic Build Android command fails with an exception after trying to add ngCordova calendar plugin

我正在 ubuntu 中使用 ionic(1.7.15)。

在我尝试实施 calendar 插件之前,我的项目工作正常。将此插件安装到我的项目后,我尝试使用 ionic build android 命令进行构建,但出现以下错误。

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

我希望以上错误是由于我的项目中有多个插件导致的].

我试过的:

我已经尝试升级我的 android SDK。

使用这个堆栈溢出问题我已经完成了所有之后我得到了上述错误。

这是我的 package.json 文件

{
  "name": "app",
  "version": "1.1.1",
  "description": "app: An Ionic project",
  "dependencies": {
    "gulp": "^3.5.6",
    "gulp-sass": "^2.0.4",
    "gulp-concat": "^2.2.0",
    "gulp-minify-css": "^0.3.0",
    "gulp-rename": "^1.2.0"
  },
  "devDependencies": {
    "bower": "^1.3.3",
    "gulp-util": "^2.2.14",
    "shelljs": "^0.3.0"
  },
  "cordovaPlugins": [
    "cordova-plugin-device",
    "cordova-plugin-console",
    "cordova-plugin-whitelist",
    "cordova-plugin-splashscreen",
    "cordova-plugin-statusbar",
    "ionic-plugin-keyboard",
    {
      "locator": "https://github.com/rossmartin/PushPlugin.git",
      "id": "com.phonegap.plugins.PushPlugin"
    }
  ],
  "cordovaPlatforms": [
    "android"
  ]
}

这是我的 fetch.json 文件

{
    "cordova-plugin-device": {
        "source": {
            "type": "registry",
            "id": "cordova-plugin-device@~1.1.1"
        },
        "is_top_level": true,
        "variables": {}
    },
    "cordova-plugin-console": {
        "source": {
            "type": "registry",
            "id": "cordova-plugin-console@~1.0.2"
        },
        "is_top_level": true,
        "variables": {}
    },
    "cordova-plugin-whitelist": {
        "source": {
            "type": "registry",
            "id": "cordova-plugin-whitelist"
        },
        "is_top_level": true,
        "variables": {}
    },
    "cordova-plugin-splashscreen": {
        "source": {
            "type": "registry",
            "id": "cordova-plugin-splashscreen"
        },
        "is_top_level": true,
        "variables": {}
    },
    "cordova-plugin-statusbar": {
        "source": {
            "type": "registry",
            "id": "cordova-plugin-statusbar@~2.1.0"
        },
        "is_top_level": true,
        "variables": {}
    },
    "ionic-plugin-keyboard": {
        "source": {
            "type": "registry",
            "id": "ionic-plugin-keyboard"
        },
        "is_top_level": true,
        "variables": {}
    },
    "cordova-plugin-camera": {
        "source": {
            "type": "registry",
            "id": "cordova-plugin-camera"
        },
        "is_top_level": true,
        "variables": {}
    },
    "phonegap-plugin-push": {
        "source": {
            "type": "registry",
            "id": "phonegap-plugin-push"
        },
        "is_top_level": true,
        "variables": {}
    },
    "com.phonegap.plugins.PushPlugin": {
        "source": {
            "type": "git",
            "url": "https://github.com/phonegap-build/PushPlugin.git",
            "subdir": "."
        },
        "is_top_level": true,
        "variables": {}
    },
    "cordova-plugin-datepicker": {
        "source": {
            "type": "git",
            "url": "https://github.com/VitaliiBlagodir/cordova-plugin-datepicker.git",
            "subdir": "."
        },
        "is_top_level": true,
        "variables": {}
    },
    "cordova-plugin-calendar": {
        "source": {
            "type": "registry",
            "id": "cordova-plugin-calendar"
        },
        "is_top_level": true,
        "variables": {}
    },
    "cordova-plugin-crosswalk-webview": {
        "source": {
            "type": "registry",
            "id": "cordova-plugin-crosswalk-webview"
        },
        "is_top_level": true,
        "variables": {}
    }
}

我不知道出了什么问题,请任何人帮助我。

您的问题是您使用的推送插件版本过时。在您的 package.json 中,您为遗留的 Ant 驱动的 Cordova 构建过程包括了 https://github.com/rossmartin/PushPlugin.git which is a unmaintained branch of a deprecated plugin that hasn't been updated in 2 years. Hence, if you look at its plugin.xml, you can see it includes the Android Support Library as a JAR

<source-file src="src/android/com/plugin/android-support-v13.jar" target-dir="libs/" />

您需要删除此版本的插件并将其替换为 up-to-date equivalent cordova-plugin-push, which uses Gradle to include the support library:

<framework src="com.android.support:support-v13:23+" />

请注意,您需要为 Android API v23 构建,因此必须通过 SDK 管理器安装它并使用 Cordova Android 平台的 v5+(cordova-android@5+).

更新

build.gradle 文件中,我添加了这几行。

在 dependencies 添加这一行 compile 'com.android.support:multidex:1.0.1'

    dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    debugCompile project(path: "CordovaLib", configuration: "debug")
    releaseCompile project(path: "CordovaLib", configuration: "release")
    compile "com.android.support:support-v4:+"
    // SUB-PROJECT DEPENDENCIES END
    compile 'com.android.support:multidex:1.0.1' 

}

默认配置添加这一行multiDexEnabled true

defaultConfig {
        versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")
        applicationId privateHelpers.extractStringFromManifest("package")

        if (cdvMinSdkVersion != null) {
            minSdkVersion cdvMinSdkVersion

        }
        multiDexEnabled true
    }

添加此行后,我得到了他的错误提示website,我通过删除platform/android/libs/解决了这个问题你可以看到"android-support-v13.jar"删除那个文件

你为项目安装的所有插件查找 plugin.xml 文件,然后检查任何指向 android-support-[ 的行=58=]然后评论或者按上面的方法做,谢谢

这里有一个简单的现成 plugin 可以为您完成 build.gradle

cordova plugin add cordova-plugin-enable-multidex

请找到此 repository link 了解更多详细信息