我无法运行我的应用程序。每次我尝试在模拟器 Android Studio 中运行我的应用程序时,都会显示以下错误。
Error:Execution failed for task ':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'' finished with non-zero exit value 2
这是我的 build.gradle
文件。
build.gradle(应用程序)
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(项目)
// 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()
}
}
我已经尝试从许多与我的问题类似的问题中应用解决方案,但我仍然无法解决我的问题。提前致谢。
最佳答案
将此添加到 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
希望对你有帮助
关于java - Gradle 构建在 Android Studio 1.5.1 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34465844/