首页 > 解决方案 > 使用android dataBinding时出错

问题描述

当我在 app/build.gradle 中启用 dataBinding 时出现问题,这给了我这个错误:“错误:无法解决:support-v4”。以下是包含依赖项和库的构建文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    dataBinding {
        enabled = true
    }
    defaultConfig {
        applicationId "com.dxhf.studio.databinding"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.0.2'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:design:27.0.2'
}

我添加了 support-v4 但它没有解决问题,删除 dataBinding 部分时也没有问题。是什么导致了问题?

更新 1. 这是我的项目级 Gradle 文件。

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
   repositories {
      google()
      jcenter()

  }
}

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

标签: androiddata-bindingbuild.gradle

解决方案


推荐阅读