【问题标题】:Gradle DSL method not found: 'dataBinding()'找不到 Gradle DSL 方法:'dataBinding()'
【发布时间】:2019-10-21 15:09:17
【问题描述】:

我是 Android 新手。在这里,我正在尝试将数据绑定添加到我的 android 应用程序,因为我启用了数据绑定到真正的应用程序内级别 gradle 文件,但问题是它没有同步它会出现类似这样的错误。

Gradle DSL method not found: 'dataBinding()'
Possible causes:
The project 'TriviaApp' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 3.4.1 and sync project

The project 'TriviaApp' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file

The build file may be missing a Gradle plugin.
Apply Gradle plugin

这是我的应用级 gradle 文件代码

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.triviaapp"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.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 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

谁能帮我找出我做错了什么并帮助我解决这个问题。

【问题讨论】:

    标签: android kotlin android-databinding


    【解决方案1】:

    你应该使用

    dataBinding {
            enabled = true
        }
    

    确保您的 build.gradle

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

    【讨论】:

      猜你喜欢
      • 2015-04-16
      • 1970-01-01
      • 2015-11-19
      • 2017-10-27
      • 2015-03-29
      • 2015-01-20
      • 2015-01-10
      • 2015-02-21
      • 1970-01-01
      相关资源
      最近更新 更多