0

I choose WorkManager to make a scheduled service that would help me post data to server when cordova based app is closed.

So, I start with including dependencies in 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
}

Now I run following commands

cordova clean
cordova build android

I get throw with an exception:

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

So, I add this line

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

I ran the clean and build commands again. Now, I get new exception:

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]))

Any help would be appreciated. Thank you

EDIT: I do get this error aswell enter image description here

wenn32
  • 1,256
  • 2
  • 17
  • 26

2 Answers2

0

for Cordova there is a Multidex Plugin while you probably just could edit the file which generates the build.gradle and enable it there... in order not to install that plugin, which does not have much purpose, but adding those two lines - which only applies for Android and no other platform.

defaultConfig {
    multiDexEnabled true
}

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

see Enable multidex for apps with over 64K methods.

building against API level > 21 should also work, because there it would be enabled by default.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Thanks for the reply Martin. Unfortunately that didn't work. I have added an update to my question with a screenshot. – wenn32 Aug 26 '18 at 10:21
0

Answering my own question if anyone faces this issue.

I did what was mentioned in this SO question:

//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'
}
wenn32
  • 1,256
  • 2
  • 17
  • 26