1

I have updated an outdated project and made changes to build gradle, basically upgraded some gradle dependencies and changed gradle version. Project build successfully when I do clean and rebuild. But, when I try to run it on device or emulator it fails to build with transformDexArchiveWithExternalLibsDexMergerForDebug error.

I have tried almost every solution from these two SO threads but still unable to make it work.

  1. Unable to Merge Dex - Android Studio 3.0

  2. Unable to merge dex

Below is my project level gradle.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        // classpath 'com.github.dcendents:android-maven-plugin:1.2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
        classpath 'com.google.gms:google-services:3.2.1'
    }
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}
dependencies {
}

ext {
    libraryVersion = "1.0.8"
}

This is app module gradle.

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.dapp.myapp"
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }
    buildTypes {

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    aaptOptions {
        cruncherEnabled = false
        useNewCruncher = false
    }

    lintOptions {
        disable 'MissingTranslation'
    }

    dexOptions {
        jumboMode true
        javaMaxHeapSize "4g"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':maskedEditText')
    implementation project(':aPV')
    //implementation files('libs/libGoogleAnalyticsServices.jar')
    //compile 'com.android.support:appcompat-v7:19.1.0'
    implementation files('libs/simple-xml-2.7.1.jar')
    implementation project(':segmentControl')
    implementation files('libs/gcm.jar')
    implementation project(':UpPlatformSdk')
    implementation files('libs/scribe-1.3.7.jar')
    implementation files('libs/signpost-commonshttp4-1.2.1.2.jar')
    implementation files('libs/signpost-core-1.2.1.2.jar')
    // compile 'com.github.PhilJay:MPAndroidChart:v2.1.0'
    implementation files('libs/joda-time-2.0.jar')
    implementation project(':MPChartLib')
    implementation files('libs/apache-httpcomponents-httpclient.jar')
    implementation files('libs/apache-httpcomponents-httpcore.jar')
    /*compile 'com.google.android.gms:play-services:8.4.0'*/
    implementation files('libs/libphonenumber-3.8.jar')
    implementation files('libs/ebizcharge-sdk.jar')
    //compile project(':slicepaymentlibrary')

    //compile project(':camerafragment')
    implementation project(':camerafragment')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.loopj.android:android-async-http:1.4.5'
    implementation 'com.android.support:customtabs:28.0.0'
    //implementation 'com.google.android.gms:play-services-identity:16.0.0'
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
}

Build log enter image description here

Full error stacktrace as pasting here is exceeding character limit

https://pastebin.com/Zukca8FM

Any help appreciated. Thanks.

karan
  • 8,637
  • 3
  • 41
  • 78

2 Answers2

0

Update your Google Services dependency:

classpath 'com.google.gms:google-services:3.3.0'

Firebase versioning style has changed, which can cause issues caused by conflicting libraries.

Jake Lee
  • 7,549
  • 8
  • 45
  • 86
  • updated to latest available 4.1.0 and invalidated and restarted android studio. still not working. btw project is using gcm and not fcm. – karan Nov 27 '18 at 10:07
  • Can you post the full stack trace as text please? – Jake Lee Nov 27 '18 at 10:07
  • sure, updating in the question. – karan Nov 27 '18 at 10:08
  • You've got a lot of custom jars in there. Can you try removing them until the error goes away? It's very likely to be a conflict, with one of them using an outdated dependency. – Jake Lee Nov 27 '18 at 10:21
  • thats the issue, project is quite old and has lot of unnecessary clutter. issue is that I cannot remove any of them as it might be used somewhere in app. – karan Nov 27 '18 at 10:26
  • You can remove them, and remove any usages, just to work out which is causing the issue. Once the problem-causing one has been identified, you can begin to work on a solution. – Jake Lee Nov 27 '18 at 10:29
  • I downgraded my gcm version to 12.0.0 and it started working. – karan Nov 27 '18 at 10:49
  • Glad you got it sorted! Feel free to mark it as solved / closed if it is. – Jake Lee Nov 27 '18 at 11:02
0

Try this project level gradle, I faced the same issue in my app, but this resolve my issue

buildscript {
repositories {
    maven {
        url 'http://jcenter.bintray.com'
        name 'Google'
    }
    google()
}

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
    classpath 'com.google.gms:google-services:3.2.1'
    classpath 'de.mobilej.unmock:UnMockPlugin:0.1.0'
    classpath 'org.aspectj:aspectjtools:1.8.9'
    classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:1.0.10'
    classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
    classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
    classpath "com.archinamon:android-gradle-aspectj:3.2.0"
    classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
    classpath 'com.jakewharton:butterknife-gradle-plugin:8.6.0'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}
allprojects {
repositories {
    google()
    jcenter()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
kuber singh
  • 289
  • 1
  • 5