On updating android stdio,Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException:

On updating android stdio,Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException:

今天我更新了我的 android stdio,然后我看到了以下错误,我无法理解这些错误的原因,但它给出了很多

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

这些也是之前的错误,

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.

这些是我的 gradle 文件,

// 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
}

这是第二个 build.gradle 文件,

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')
}

请帮帮我。

造成这种情况的原因之一是当您到达 65K method limit 时。 您可以通过删除未使用的 code/libraries 来解决此问题。为此,您需要查看您的依赖项。要列出您的依赖项,您可以执行

gradlew -q dependencies app:dependencies --configuration compile

项目根目录中的命令。

或者如果没有 code/libraries 可以删除,您可以使用 multidex 支持

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

并在 defaultConfig 中将 multiDexEnabled 设置为真

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

您还需要通过将 android:name="android.support.multidex.MultiDexApplication" 添加到应用程序标签来引用清单中的 MultiDexApplication class。

注意: 如果相反,您的应用扩展了 Application class,您可以覆盖 attachBaseContext() 方法并调用 MultiDex.install(this) 启用 multidex,像这样。

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

有关详细信息,请参阅此 answer and this

将此添加到您的应用中 gradle 依赖项

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

将此添加到您的默认配置中

  multiDexEnabled true

将此添加到您的应用程序 gradle

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

同步应用程序

最后在 Manifest 文件中的应用程序中添加以下内容

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

并像这样在 defaultConfig 中将 multiDexEnabled 设置为 true

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.

注意:如果相反,您的应用程序扩展了应用程序 class,您可以覆盖 attachBaseContext() 方法并调用 MultiDex.install(this) 来启用 multidex,就像这样。

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

}

您似乎使用了不同版本的 Android 支持库(23.0.1 和 23.1.1)。也许你应该尝试使用相同的版本。

此外,如前所述,列出您的依赖项以检查它们是否使用与您支持库相同的版本:

./gradlew app:dependencies --configuration compile

它总是会发生,因为您仅为发布版本启用了 multiDex,而不是调试版本。

试试这个:

defaultConfig {
    multiDexEnabled true
}