Android Studio 返回 运行 应用程序时出现此错误 3 Java

Android Studio this error 3 Java when returning to Run the application

运行应用程序按返回此错误:

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

我的项目有 lib facebook sdk 和 wheellib。 我意识到 Android Studio 处理 Gradle 的时间很长,之后显示此错误并且应用程序从未启动 (运行)

我的gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId 'br.com.myproject'
        minSdkVersion 19
        targetSdkVersion 23
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile project(':facebookSDK')
    compile project(':wheellib')
    compile files('libs/comscore.jar')
    compile files('libs/FlurryAnalytics-5.5.0.jar')
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.picasso:picasso:2.3.2'
    compile 'joda-time:joda-time:2.4'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile 'com.google.android.gms:play-services-identity:8.3.0'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
}

您必须在您的终端运行此命令:

your-project-directory:$> gradle build --info --stacktrace 

然后您将看到 gradle 任务失败的确切时刻。

我认为问题在于您可能面临 64k 方法限制。

我今天也遇到了这个问题,它在 SDK 中只需要 JDK 1_7 !我把它加在gradle

compileOptions {
        //noinspection GroovyAssignabilityCheck
        sourceCompatibility JavaVersion.VERSION_1_7
        //noinspection GroovyAssignabilityCheck
        targetCompatibility JavaVersion.VERSION_1_7
    }

然后将计算机上的 HOME_JAVA 更改为 JDK 版本 1_7 并将 Android Studios 项目结构中的 Java 版本更改为 1_7这就是我所做的一切。 您可能只是检查所有 JDK 要求的兼容性,或者它也可能是 64+ 方法问题...

我改变了我的 build.gradle 并开始工作!添加了 dexOptions:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId 'br.com.myproject'
        minSdkVersion 19
        targetSdkVersion 23
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    compileOptions {
        //noinspection GroovyAssignabilityCheck
        sourceCompatibility JavaVersion.VERSION_1_7
        //noinspection GroovyAssignabilityCheck
        targetCompatibility JavaVersion.VERSION_1_7
    }
    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile project(':facebookSDK')
    compile project(':wheellib')
    compile files('libs/comscore.jar')
    compile files('libs/FlurryAnalytics-5.5.0.jar')
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.squareup.picasso:picasso:2.3.2'
    compile 'joda-time:joda-time:2.4'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile 'com.google.android.gms:play-services-identity:8.3.0'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
}