【问题标题】:Ionic Build Android command fails with an exception after trying to add ngCordova calendar plugin尝试添加 ngCordova 日历插件后,Ionic Build Android 命令失败并出现异常
【发布时间】:2016-05-31 06:16:56
【问题描述】:

我在 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;

我希望由于我的项目中的多个插件而出现上述错误有什么解决办法。我发现这个错误与here中的multidex有关。

我尝试过的:

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

使用这个堆栈溢出问题Could not resolve all dependencies for configuration ':_armv7DebugCompile' 我已经完成了所有操作,之后我得到了上述错误。

这是我的 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": {}
    }
}

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

【问题讨论】:

  • 我认为@EmptyCup 是正确的:您可能有一个插件,包括作为JAR 的Android 支持库,然后是这个日历插件includes it as a Gradle dependency。如果您发布您正在使用的所有插件的列表,或者发布您的config.xml,这将有所帮助
  • @DaveAlden 我已经用 config.xml 更新了我的问题
  • 抱歉,忘记使用 Ionic:如果您使用的是 ionic plugin add,请发帖 package.json 或发帖 plugins/fetch.json
  • @DaveAlden 检查我更新的问题

标签: angularjs ionic-framework ngcordova android-multiple-users


【解决方案1】:

您的问题是您使用的是过时版本的推送插件。从您的package.json 中,您包括https://github.com/rossmartin/PushPlugin.git,这是一个已弃用的插件的未维护分支,该插件已在 2 年内未更新。因此,如果您查看它的 plugin.xml,您可以看到 includes the Android Support Library as a JAR 用于旧版 Ant 驱动的 Cordova 构建过程:

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

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

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

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

更新

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

在依赖项中添加这一行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-v13.jar 的任何行并对其进行注释或按上述操作,谢谢你

【讨论】:

  • ngcordova.com/docs/plugins/pushNotifications检查这个网站我使用这个插件来安装推送通知
  • 我没有下载任何离子插件并添加到我的项目中我使用我的 cmd 来安装我所有由ngcordova.com/docs/plugins提供的cordova插件
  • 我在我的 config.xml 文件中添加了&lt;framework src="com.android.support:support-v13:23+" /&gt;,我尝试构建它,但我仍然遇到同样的错误
  • 不管插件是如何安装的,您的问题仍然是您安装了不兼容的推送插件版本,它使用了 Android 支持库的 JAR 版本(您可以通过手动检查plugins/ 文件夹)。这将与通过 Gradle 包含支持库的任何其他插件发生冲突,因此您的构建错误。将&lt;framework&gt; 标记添加到config.xml 将不起作用-它仅由plugin.xml 包含处理。
  • 谢谢,但是在我在我的`build.gradle'文件中添加了两行之后,你的回答工作了,这个错误让我很生气,但你的思维方式对我很有帮助,谢谢
【解决方案2】:

这是一个简单的现成plugin,它可以为您工作build.gradle

cordova plugin add cordova-plugin-enable-multidex

更多详情请查看repository link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-17
    • 2023-03-03
    • 1970-01-01
    • 2018-08-26
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    • 2019-12-14
    相关资源
    最近更新 更多