【问题标题】:Gradle build failed in Android Studio 1.5.1Android Studio 1.5.1 中的 Gradle 构建失败
【发布时间】:2016-03-31 16:03:32
【问题描述】:

我无法运行我的应用程序。每次我尝试在模拟器 Android Studio 中运行我的应用时,都会显示以下错误。

错误:任务 ':app:transformClassesWithDexForDebug' 执行失败。> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException : Process 'command 'C:\Program Files (x86)\Java\jdk1.8.0_66\bin\java.exe'' 以非零退出值 2 结束

这是我的 build.gradle 文件。

build.gradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId "com.gripxtech.kasim.unipayretailer"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName '1.0'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.malinskiy:superrecyclerview:1.1.1'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.codinguser.android:contactpicker:3.0.0@aar'
    compile 'com.squareup.okhttp:okhttp:2.7.0'
    compile project(':materialdatetimepick')
}



build.gradle(Project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}


我已经尝试从许多与我类似的问题中应用解决方案,但是我仍然无法解决我的问题。提前致谢。

【问题讨论】:

  • 你尝试清理项目了吗?
  • 是的,我试过清理而不是重建项目。但是,这对我不起作用。目前我正在尝试创建新项目,而不是在新创建的项目中复制我的所有文件。希望这对我有用。

标签: java android android-studio android-gradle-plugin


【解决方案1】:

将此添加到build.gradle 文件:

android {
...
defaultConfig {
    ...
    multiDexEnabled true
    }
}

您可以在此处找到发生此错误的原因: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define

如果不起作用,请删除以下所有文件和文件夹:

YOUR_APP_NAME\app\build\intermediates

当你有不同版本的重复依赖项时,有时会发生这种情况

试试这个命令,看看有没有问题两次:

./gradlew dependencies

希望对你有帮助

【讨论】:

  • 它就像魅力一样。非常感谢
猜你喜欢
  • 2016-04-05
  • 2020-10-16
  • 1970-01-01
  • 1970-01-01
  • 2013-06-13
  • 2015-02-06
  • 1970-01-01
  • 1970-01-01
  • 2016-02-04
相关资源
最近更新 更多