数据绑定错误的androidx:包android.support.constraint不存在

时间:2018-12-03 11:13:49

标签: android gradle android-jetpack androidx

我正在学习databinding,并试图将新的库结构用作androidx。 当我尝试构建项目时,遇到了这个错误。

  

错误:程序包android.support.constraint不存在

此错误在Binding生成的文件中为

public class ActivityMainBindingImpl extends ActivityMainBinding  {
    @Nullable
    private static final androidx.databinding.ViewDataBinding.IncludedLayouts sIncludes;
    @Nullable
    private static final android.util.SparseIntArray sViewsWithIds;
    static {
        sIncludes = null;
        sViewsWithIds = null;
    }
    // views
    @NonNull
    private final android.support.constraint.ConstraintLayout mboundView0;
    @NonNull
    private final android.widget.TextView mboundView1;

这是我的build.gradle应用模块。

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.climesoft.learn.livedatabinding"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.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.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

这是build.gradle项目模块。

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.10'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // 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
}

最后一个gradle.properties文件是这个。

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

android.useAndroidX=true

android.enableJetifier=true

那么,为什么Android Studio不使用androidx.constraintlayout包生成Binding类?

3 个答案:

答案 0 :(得分:8)

android.support.constraint表示您使用的是支持库,而不是AndroidX。

您可能应该将android.support.constraint.ConstraintLayout中的androidx.constraintlayout.widget.ConstraintLayout更改为activity_main.xml

答案 1 :(得分:0)

使用androidx,软件包名称已更改。原来android.support现在是androidx。通常,当您将项目转换为androidx / jetpack时,AndroidStudio会自动对其进行更改。 Build ...菜单中某处有一个选项。

答案 2 :(得分:0)

如果你使用

com.heinrichreimersoftware:material-intro:x.x.x

尝试改变:

implementation 'com.heinrichreimersoftware:material-intro:master-SNAPSHOT'