【问题标题】:Android Resourcse linking Failed while using : buildFeatures {viewBinding = true}Android资源链接使用失败:buildFeatures {viewBinding = true}
【发布时间】:2020-06-10 15:32:21
【问题描述】:

今天开了一个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】:

    我已经解决了这个问题。我不得不将我的资源移动到 drawable-v24 文件夹。而已。但是,不要因为昨天一切正常而需要它。也许更新与它有关。我会寻找原因,如果我想出什么,我会发布。

    【讨论】:

    • 你能提供更多关于你的解决方案的细节吗?我试图在 android 中添加构建功能,但我仍然有警告......我找不到解决方案(我尝试了很多不同的语法,但没有任何效果)。谢谢
    • OK 解决了,我只需要删除这个旧行:viewBinding.enabled = true,然后将其替换为:android.buildFeatures.viewBinding = true
    • 很高兴听到。快乐编码
    猜你喜欢
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多