将activity_main.xml转换为数据绑定布局时,如何解决“ androidx。*…* .ConstraintLayout”问题?

问题描述 投票:0回答:1

build.gradle中的DataBinding配置为“ enabled = true”,但是当我将constraintlayout转换为数据绑定布局并且不执行任何其他操作时,编译器始终显示“ Element androidx.constraintlayout.widget.ConstraintLayout此处不允许。”

基本信息:Android Studio 3.5.1;内部版本#AI-191.8026.42.35.5900203,于2019年9月26日建立;JRE:1.8.0_202-release-1483-b03 amd64;JVM:JetBrains s.r.o的OpenJDK 64位服务器VM;Windows 10

如果我使用其他布局,例如linearlayout,framelayout等,编译器不会出错。 Kotlin可以成功生成此错误(但应用程序无法按预期运行),而Java则无法,我尝试清理生成,多次重新启动AS和PC,但是编译器仍然显示此错误。我想知道这是AS 3.5的错误,还是做错了什么?请帮助我,谢谢。

    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.example.app15"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        dataBinding{
            enabled = true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
}
java android-studio kotlin data-binding android-constraintlayout
1个回答
0
投票

如果进行更改后看到编译器错误,请选择Build> Clean Project,然后选择Build> Rebuild

这样做通常会更新生成的文件。否则,选择文件>使高速缓存无效/重新启动进行更彻底的清除。

© www.soinside.com 2019 - 2024. All rights reserved.