找不到com.android.databinding:compiler.3.4.0

时间:2019-05-04 03:29:26

标签: android android-studio kotlin

大家好,我们如何在android_plugin_version ='3.4.0'中启用数据绑定?作为我的Android Studio,我安装了最新版本,并将android_plugin_version ='3.4.0'降级为3.2.xx时收到另一个错误。

项目gradle

buildscript {
ext {
    kotlin_version = '1.3.31'
    android_plugin_version = '3.4.0'
}
repositories {
    google()
    jcenter()
    maven { url 'https://maven.google.com' }
}
dependencies {
    classpath "com.android.tools.build:gradle:$android_plugin_version"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  }
}

allprojects {
repositories {
    google()
    jcenter()
    mavenCentral()
 }
}

模块

 apply plugin: 'com.android.application'

 apply plugin: 'kotlin-android'

 apply plugin: 'kotlin-android-extensions'

 apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
    applicationId "xxx.xxx.com"
    minSdkVersion 21
    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
}

kapt {
    generateStubs = 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'

   kapt "com.android.databinding:compiler:$android_plugin_version"
}

同步没有问题,但是在运行时,我收到此错误

Could not find com.android.databinding:compiler:3.4.0.
Searched in the following locations:

-

https://dl.google.com/dl/android/maven2/com/android/databinding/compiler/3.4.0/compiler-3.4.0.pom   -https://dl.google.com/dl/android/maven2/com/android/databinding/compiler/3.4.0/compiler-3.4.0.jar   -https://jcenter.bintray.com/com/android/databinding/compiler/3.4.0/compiler-3.4.0.pom   -https://jcenter.bintray.com/com/android/databinding/compiler/3.4.0/compiler-3.4.0.jar   -https://repo.maven.apache.org/maven2/com/android/databinding/compiler/3.4.0/compiler-3.4.0.pom   -https://repo.maven.apache.org/maven2/com/android/databinding/compiler/3.4.0/compiler-3.4.0.jar

4 个答案:

答案 0 :(得分:1)

您使用了错误版本的数据绑定编译器。对于最新版本,您可以检查诸如mvnrepository之类的网站。目前,最新版本为3.4.0。 在这里,您传递的版本错误:

 kapt "com.android.databinding:compiler:$android_plugin_version"

相反,请使用:

kapt "com.android.databinding:compiler:3.4.0"

更新

在Android Studio 3.3及更高版本中,您无需添加注释处理器kapt "com.android.databinding:compiler:$android_plugin_version"。只需在模块gradle文件中设置dataBinding.enabled = true即可,或者像这样:

android {
    ...
    dataBinding {
        enabled = true
    }
}

答案 1 :(得分:1)

我只是删除了kapt“ com.android.databinding:compiler $ android_plugin_version”,它使ActivityMainBinding出现在我的MainActivity中

Gradle应用

    apply plugin: 'com.android.application'

     apply plugin: 'kotlin-android'

     apply plugin: 'kotlin-android-extensions'

     apply plugin: 'kotlin-kapt'

     android {
        compileSdkVersion 28
        defaultConfig {
        applicationId "xxx.xx.com"
        minSdkVersion 21
        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'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dataBinding {
        enabled = true
    }
}

kapt {
    correctErrorTypes = 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'
}

答案 2 :(得分:0)

转到文件>>设置>> Gradle >> android studio并检查嵌入式maven

答案 3 :(得分:0)

更新gradle插件。

它对我有用