【问题标题】:Cordova + WorkManager exceptionCordova + WorkManager 异常
【发布时间】:2018-08-28 13:52:44
【问题描述】:

我选择 WorkManager 来制定一项计划服务,当基于 cordova 的应用程序关闭时,该服务将帮助我将数据发布到服务器。

所以,我首先在 build.gradle (Module:app) 中包含依赖项

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')

    //THIS LINE HERE IS FOR WORKMANAGER
    implementation "android.arch.work:work-runtime:1.0.0-alpha01"

    // SUB-PROJECT DEPENDENCIES START
    implementation(project(path: ":CordovaLib"))
    compile "com.android.support:support-v4:24.1.1+"
    // SUB-PROJECT DEPENDENCIES END
}

现在我运行以下命令

cordova clean
cordova build android

我抛出异常:

任务执行失败 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: 无法合并 索引

所以,我添加了这一行

android {

    defaultConfig {
        versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
        applicationId privateHelpers.extractStringFromManifest("package")

        //THIS LINE HERE
        multiDexEnabled true

        if (cdvMinSdkVersion != null) {
            minSdkVersion cdvMinSdkVersion
        }
    }

    lintOptions {
      abortOnError false;
    }

    compileSdkVersion cdvCompileSdkVersion
    buildToolsVersion cdvBuildToolsVersion

我再次运行了 clean 和 build 命令。 现在,我得到了新的例外:

Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> java.io.IOException: Can't write [C:\Users\hjhkjn\Desktop\cordova\hjhkjnad\platforms\android\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\hjhkjn\Desktop\cordova\hjhkjnad\platforms\android\app\build\intermediates\transforms\desugar\debug\19.jar(;;;;;;**.class)] (Duplicate zip entry [19.jar:android/support/v4/content/PermissionChecker$PermissionResult.class]))

任何帮助将不胜感激。谢谢

编辑: 我也收到此错误

【问题讨论】:

    标签: android cordova android-workmanager


    【解决方案1】:

    对于 Cordova,有一个 Multidex Plugin,而您可能只需要编辑生成 build.gradle 的文件并在那里启用它...为了不安装没有太多用途的插件,但添加那些两行 - 仅适用于 Android,不适用于其他平台。

    defaultConfig {
        multiDexEnabled true
    }
    
    dependencies {
        implementation 'com.android.support:multidex:1.0.3'
    }
    

    Enable multidex for apps with over 64K methods

    针对 API 级别 > 21 构建也应该可以工作,因为它会默认启用。

    【讨论】:

    • 感谢马丁的回复。不幸的是,这并没有奏效。我已经用截图更新了我的问题。
    【解决方案2】:

    如果有人遇到此问题,请回答我自己的问题。

    我做了这个 SO 问题中提到的事情:

    //https://stackoverflow.com/questions/47185549/unable-to-merge-dex-when-using-room
    //adding the following to the root level of the Gradle file
    
    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-04
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      • 2014-09-20
      • 2016-04-09
      • 1970-01-01
      • 2016-12-18
      • 2013-11-18
      相关资源
      最近更新 更多