0

I am having Error Unable to merge dex in my project. i applied different answers from StackOverFlow like:

 defaultConfig {
    multiDexEnabled true
}
dependencies {
    compile 'com.android.support:multidex:1.0.1'}
<application
    android:name="android.support.multidex.MultiDexApplication"

and applied in manifest as well.i cleaned project Rebuild /MakeProject and applied all other option provided by users in answers but getting that error. when i enable multidex then i got list of errors converting byte to dex. I don't know what i am missing in that. here is my App Gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.example.hp_pc.cerv"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    dexOptions {
        preDexLibraries = false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
//    compile files('libs/httpclient-4.2.3.jar')
//    compile files('libs/httpmime-4.3.jar')
//    compile files('libs/httpcore.jar')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.mcxiaoke.volley:library:1.0.+'
    compile 'com.github.pinball83:masked-edittext:1.0.3'
   // compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.wdullaer:materialdatetimepicker:2.5.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'joda-time:joda-time:2.9.4'
    testCompile 'junit:junit:4.12'
}

and here is my Project Gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Zaigham Raza
  • 364
  • 2
  • 3
  • 14

1 Answers1

0

If you are using Google Service then your Project gradle should look like this-

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And for handling the Multidexing and using Google service your App gradle should look like this-

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.example.hp_pc.cerv"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    dexOptions {
        preDexLibraries = false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
//    compile files('libs/httpclient-4.2.3.jar')
//    compile files('libs/httpmime-4.3.jar')
//    compile files('libs/httpcore.jar')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.+'
    compile 'com.github.pinball83:masked-edittext:1.0.3'
   // compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.wdullaer:materialdatetimepicker:2.5.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'joda-time:joda-time:2.9.4'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

And add these two lines in your AndroidManifest file inside tag-

<application
    android:hardwareAccelerated="true"
    android:largeHeap="true"

hope it will resolve your problem.

D_Alpha
  • 4,039
  • 22
  • 36
  • now i am having error Google-Service Json is missing – Zaigham Raza Dec 20 '17 at 12:13
  • add the google-services.json file to resolve this, you missed this file. Add it to the app/ directory. follow this link- https://support.google.com/firebase/answer/7015592 – D_Alpha Dec 20 '17 at 13:13
  • i am not using firebase in that project i am using just google maps and location API's. IDK why it is asking for json services file – Zaigham Raza Dec 20 '17 at 13:25