2

This is my build.gradle

android {
    ...
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        ...
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 2
        versionName "1.4.0"
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
    }
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile(name: 'identitytoolkit-api11', ext: 'aar')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile ([group: 'com.google.api-client', name: 'google-api-client-android', version: '1.21.0'])
    compile 'com.android.support:multidex:1.0.0'
}

I get this error:

Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_80\bin\java.exe'' finished with non-zero exit value 2

I use google endpoints and I generate the API libraries using this doc. And include the jar file to libs folder.

I get this error and I don't even know how to get more info and what to do to come over.

The solution:

android {
    ...
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        ...
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 2
        versionName "1.4.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
    }
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile(name: 'identitytoolkit-api11', ext: 'aar')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services-maps:8.3.0'
    compile ([group: 'com.google.api-client', name: 'google-api-client-android', version: '1.21.0'])
}
Thanassis
  • 857
  • 1
  • 8
  • 25
  • does your application extend `MultiDexApplication`? – Adeeb Dec 10 '15 at 10:03
  • No I don't think so.. Can you give me some more info? – Thanassis Dec 10 '15 at 10:04
  • I hope u have already seen this http://stackoverflow.com/questions/18021901/android-studio-gradle-build-fails-execution-failed-for-task-dexdebug check u r using duplicate libs? – Raghavendra Dec 10 '15 at 10:05
  • please look at [docs](http://developer.android.com/tools/building/multidex.html), you will see that `multiDexEnabled = true` is not the only thing it mentions. It goes on further and says "In your manifest add the MultiDexApplication class from the multidex support library to the application element." – Adeeb Dec 10 '15 at 10:08
  • 1
    Read http://stackoverflow.com/questions/33313101/dexindexoverflowexception-only-when-running-tests?answertab=active#tab-top – IntelliJ Amiya Dec 10 '15 at 10:08
  • Is it possible unused object in jar file cause the problem? – Thanassis Dec 10 '15 at 10:32
  • If you include `Google Play Services`, make sure you only include the module you need, because otherwise you'll almost immediately exceed 65k. ( `compile 'com.google.android.gms:play-services:8.3.0'` ) https://developers.google.com/android/guides/setup – EpicPandaForce Dec 10 '15 at 12:03
  • Thanks! This is the solution that I found. – Thanassis Dec 10 '15 at 12:06

2 Answers2

5

In my case I just replaced

compile 'com.google.android.gms:play-services:8.3.0'

with

compile 'com.google.android.gms:play-services-maps:8.3.0'

because over 65K Methods were included.

iCantSeeSharp
  • 3,880
  • 4
  • 42
  • 65
Thanassis
  • 857
  • 1
  • 8
  • 25
1

Check multidexenable true in defaultconfig and have application class in you app and then --> extend it via MultidexApplication and use below line in your oncreate method of application:-

Multidex.install(this);

EDIT:-

--> also there is another line that if heapsize or gcoverhead exceeds issue occurs then below line will be usefull for you :-

dexOptions {
javaMaxHeapSize "4g"
}
Hardy
  • 2,576
  • 1
  • 23
  • 45
  • For the moment the correct solution is to include only the libraries needed. Thank you, I will surely consider this approach if the limit is reached and beyond. – Thanassis Dec 10 '15 at 11:50