Android资源链接在使用时失败:buildFeatures {viewBinding = true}

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

今天开始开设Android Studio之后,我遇到了一个奇怪的问题。有人说

DSL元素'android.viewBinding.enabled'已过时,并且已经] 已替换为'android.buildFeatures.viewBinding'。

经过一番寻找,我发现我必须使用

buildFeatures {viewBinding = true}

相反。因此,我用上面的替换了viewBinding {enabled = true}。之后,真正的问题开始了。 AAPT无法再检测我的绘图。这是我的buildScript:

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'

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

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }

    }
}

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

和build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.techtrixbd.RestaurantApp"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    buildFeatures {viewBinding = true}
}

我不知道发生了什么。任何建议都会有很大帮助。

android gradle aapt android-viewbinding
1个回答
0
投票

我已经解决了这个问题。我必须将资源移动到drawable-v24文件夹。而已。但是,请不要这样做,因为昨天一切正常。也许更新与此有关。我会寻找原因,并在出现问题时发布。

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