在构建文件中启用dataBinding会使transformDexArchiveWithExternalLibsDexMergerForDebug任务失败

时间:2019-05-08 03:46:15

标签: android gradle

我遇到一个非常奇怪的错误。由于某些原因,每当我尝试在构建文件中启用数据绑定时,transformDexArchiveWithExternalLibsDexMergerForDebug任务都会失败,并出现以下异常:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

我不太清楚这两件事是如何联系的。这是我的构建文件,我实际上只是创建了一个活动为空的新项目,并尝试启用数据绑定。

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.shank.dbtest"
        minSdkVersion 28
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.core:core-ktx:1.1.0-alpha05'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}

gradle.properties文件:

org.gradle.jvmargs=-Xmx1g
android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official

删除dataBinding { enabled = true }使一切正常。启用multidex无效。删除=也没有任何作用。该项目使用gradle版本4.10.1(在android studio中创建新项目时的默认设置)。不幸的是,我也正在使用Windows 10。

有人有什么想法吗?

编辑:

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

root build.gradle

buildscript {
    ext.kotlin_version = '1.3.31'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

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

1 个答案:

答案 0 :(得分:1)

如下所示在gradle-wrapper.properties中更新您的distributionUrl:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

并更新tools.build:gradle在项目级别gradle

classpath 'com.android.tools.build:gradle:3.3.2'
相关问题