3

I didn't added any libraries / jars in my project( in libs ) only this dependencies.

My build.gradle file.

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.android.example23"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
     }
 }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.melnykov:floatingactionbutton:1.1.0'
compile 'com.android.support:design:23.1.1'
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.parse:parse-android:1.11.0'
compile 'com.naver.android.helloyako:imagecropview:1.0.3'
compile 'com.squareup.okhttp:okhttp:2.6.0'
}

Once I am adding this " compile 'com.squareup.okhttp:okhttp:2.6.0' " into my project I am getting this

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.8.0_45\bin\java.exe'' finished with non-zero exit value 2

Error is coming while I run my project....

If I remove this " compile 'com.squareup.okhttp:okhttp:2.6.0' " dependency my program is working fine.

Sometimes if I added Facebook dependency also the same error is coming...

enter image description here

Anvesh523
  • 368
  • 6
  • 18

3 Answers3

3

At first you can use compile 'com.squareup.okhttp:okhttp:2.5.0' instead of yours . You can read my answer DexIndexOverflowException

android {
    compileSdkVersion 23
buildToolsVersion "23.0.1"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true
         }
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
}

http://developer.android.com/intl/es/tools/building/multidex.html

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • @Ram23 Did you add `multiDexEnabled` ? Then clean,Build & Sync your project – IntelliJ Amiya Nov 23 '15 at 05:43
  • Just now I added " multiDexEnabled true ". now I am getting new exception with java.lang.NoClassDefFoundError: android.support.v7.appcompat am checking this Thank you @IntelliJ Amiya – Anvesh523 Nov 23 '15 at 05:49
  • @Ram23 https://www.google.co.in/search?q=java.lang.NoClassDefFoundError%3A+android.support.v7.appcompat&oq=java.lang.NoClassDefFoundError%3A+android.support.v7.appcompat&aqs=chrome..69i57.695j0j7&sourceid=chrome&es_sm=93&ie=UTF-8 – IntelliJ Amiya Nov 23 '15 at 05:52
  • `compile 'com.android.support:appcompat-v7:23.0.0'` – IntelliJ Amiya Nov 23 '15 at 05:55
  • I added appcompat-v7 in my build.gradle. That's the first dependency.... in my project – Anvesh523 Nov 23 '15 at 06:01
  • yes yes .I checked .You used `v7:23.1.1'` i proposed `v7:23.0.0'` – IntelliJ Amiya Nov 23 '15 at 06:02
  • 1
    I changed to 23.0.0, Now I got new " java.lang.NoClassDefFoundError: com.parse.GcmRegistrar$Singleton " error in parse .... :( :( .. – Anvesh523 Nov 23 '15 at 06:09
  • At the end I am getting one by one error with "java.lang.NoClassDefFoundError:" .... After added multiDexEnabled, So do U have any idea with this relation between these two... – Anvesh523 Nov 23 '15 at 06:12
  • this occurs when the intended class is not found in the Class Path. – IntelliJ Amiya Nov 23 '15 at 06:13
  • 1
    @Ram23 Mine real pleasure .You can read my answer http://stackoverflow.com/questions/33313101/dexindexoverflowexception-only-when-running-tests?answertab=active#tab-top – IntelliJ Amiya Nov 23 '15 at 13:29
  • HI @IntelliJ Amiya I am getting a new problem, when I added " compile 'com.koushikdutta.ion:ion:2.1.6' " dependency I am getting " 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.8.0_45\bin\java.exe'' finished with non-zero exit value 3 " this error please help me out... ( In libs folder nothing (jar) I added ) – Anvesh523 Nov 27 '15 at 10:32
  • please post this as a question – IntelliJ Amiya Nov 27 '15 at 10:38
  • 1
    Ok, Thank you @IntelliJ Amiya – Anvesh523 Nov 27 '15 at 10:45
3

you can use below code also with IntelliJ Amiya answer. In some case this code work for me

 dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

android {
compileSdkVersion 23
 buildToolsVersion "23.0.1"

     defaultConfig {
         minSdkVersion 14 //lower than 14 doesn't support multidex
         targetSdkVersion 22

         // Enabling multidex support.
         multiDexEnabled true
     }
}

you can do by make an Application class

public class MyApplication extends MultiDexApplication { .. }

or

override 
 attachBaseContext method and call MultiDex.install().
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

Otherwise (if your application does not have custom Application implementation), declare MultiDexApplication as application implementation in your AndroidManifest.xml.

<application
android:name="android.support.multidex.MultiDexApplication"
.. >
..
</application>
curiousMind
  • 2,812
  • 1
  • 17
  • 38
  • Thank you for ur support @Aashvi I added " multiDexEnabled true ", error is gone. Now I am getting new error with java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout – Anvesh523 Nov 23 '15 at 05:59
  • @Ram23 I added some other way also which can help you in this error – curiousMind Nov 23 '15 at 06:05
  • Small suggestion in ur answer add a note somwthing like with "multiDexEnabled true" in build.gradle. – Anvesh523 Nov 23 '15 at 06:30
  • i didn't added because IntelliJ Amiya already added that answer . but i am updated now – curiousMind Nov 23 '15 at 06:31
  • 2
    S, @IntelliJ Amiya added .... Half answer in that post and half in ur post... so, that's y.... I told ... – Anvesh523 Nov 23 '15 at 06:35
  • Hi @Aashvi I am getting a new problem, when I added " compile 'com.koushikdutta.ion:ion:2.1.6' " dependency I am getting " 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.8.0_45\bin\java.exe'' finished with non-zero exit value 3 " this error Please help me out ( In libs folder nothing (jar) I added ) – Anvesh523 Nov 27 '15 at 10:32
  • @A-n-v-e-s-h i am not familiar with this error. so i can't help you. but can suggest this link : http://stackoverflow.com/questions/29720831/finished-with-non-zero-exit-value-3/30930734#30930734 – curiousMind Nov 27 '15 at 10:39
0

add

useLibrary  'org.apache.http.legacy'

in your gradle before the compileSdkversion...

Rishad Appat
  • 1,786
  • 1
  • 15
  • 30