1

我在 ubuntu 中工作 ionic(1.7.15)。

在我尝试实现日历插件之前,我的项目运行良好。将此插件安装到我的项目后,我尝试使用ionic build android命令进行构建,但出现以下错误。

在此处输入图像描述

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

我希望由于我的项目中的多个插件而发生上述错误是否有任何解决方案。我发现这个错误与multidex这里有关。

我试过的:

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

使用此堆栈溢出问题无法解决配置“:_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": {}
    }
}

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

4

2 回答 2

2

您的问题是您使用的是过时版本的推送插件。从您的package.json中,您包括https://github.com/rossmartin/PushPlugin.git这是一个已弃用的插件的未维护分支,该插件已在 2 年内未更新。因此,如果您查看它plugin.xml,您会发现它包含 Android 支持库作为旧版 Ant 驱动的 Cordova 构建过程的 JAR:

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

您需要删除此版本的插件并将其替换为最新的等效 cordova-plugin-push版本,它使用 Gradle 来包含支持库

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

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

更新

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
    }

添加此行后,我得到了他的错误参考这个网站,我通过删除 平台/android/libs/解决了它你可以看到“android-support-v13.jar”删除该文件

您为项目安装的所有插件都查找plugin.xml文件,然后检查冷藏到该 android-support-v13.jar 的任何行并对其进行评论或按上述操作,谢谢

于 2016-05-31T10:44:46.650 回答
0

这是一个简单的现成插件build.gradle可以为您完成工作

cordova plugin add cordova-plugin-enable-multidex

请找到此存储库链接以获取更多详细信息

于 2018-07-16T12:45:43.990 回答