Today when i had updated my android stdio , then i had seen following error , i can not understand cause for these error but it is giving a lot of

truble . 
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

and these is also under previous error ,

Error:Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
AGPBI: {"kind":"simple","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","sources":[{}]}
AGPBI: {"kind":"simple","text":"com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:277)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:245)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.Main.main(Main.java:106)","sources":[{}]}

FAILURE: Build failed with an exception.

* What went wrong:
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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

These is my gradle file ,

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

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1' 
}
buildscript {
    repositories {
        jcenter()
         mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.10.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
         mavenCentral()
    }
}

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

These is second build.gradle file ,

apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.shubham.MeraIndore"
        minSdkVersion 12
        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.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.androidanimations:library:1.0.3@aar'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile project(':library')
}

Please help me .

5

There are 5 best solutions below

0
On BEST ANSWER

it always happens because you enabled multiDex for release builds only, not for debug builds.

Try this:

defaultConfig {
    multiDexEnabled true
}
0
On
 dependencies {
...
// add this since you are using minSdkVersion less than 21
compile 'com.android.support:multidex:1.0.1'
 }

and set multiDexEnabled to true in defaultConfig like this

defaultConfig {
applicationId "com.shubham.MeraIndore"
minSdkVersion 12
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true

}

 You also need to reference the MultiDexApplication class in your manifest    by adding      android:name="android.support.multidex.MultiDexApplication" to application tag.

Note: If instead, your app extends the Application class, you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex, like this.

 @Override
 protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);

}

0
On

You seem to use different versions of the Android support library (23.0.1 and 23.1.1). Maybe you should try to use the same version.

Also, as suggested before, list your dependencies to check that they use the same versions as you of the support library:

./gradlew app:dependencies --configuration compile
0
On

One of the causes for this is when you reach the 65K method limit. You can solve this by either removing unused code/libraries. For that you need to have a look at your dependencies. To list your dependencies you can execute

gradlew -q dependencies app:dependencies --configuration compile

command in your project's root directory.

Or if there are no code/libraries to remove, you can use multidex support

dependencies {
    ...
    // add this since you are using minSdkVersion less than 21
    compile 'com.android.support:multidex:1.0.1'
}

and set multiDexEnabled to true in defaultConfig like this

defaultConfig {
    applicationId "com.shubham.MeraIndore"
    minSdkVersion 12
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

You also need to reference the MultiDexApplication class in your manifest by adding android:name="android.support.multidex.MultiDexApplication" to application tag.

Note: If instead, your app extends the Application class, you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex, like this.

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

For more details, see this SO answer and this.

1
On

add this in your app gradle dependencies

compile 'com.android.support:multidex:1.0.1'

add this in your defaultConfig

  multiDexEnabled true

add this to your app gradle

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

sync app

and finally add following to application in Manifest file

   android:name="android.support.multidex.MultiDexApplication"