在 build.gradle 文件中添加 buildFeatures 时出错 [英] Error when adding buildFeatures in build.gradle file

查看:99
本文介绍了在 build.gradle 文件中添加 buildFeatures 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 compose,这是 Andorid jetpack 中的一项新功能.下面是我的代码.我在 app 的 build.gradle 文件中添加 buildfeatures,而不是在根文件夹中.

I am trying out compose which is a new feature in Andorid jetpack. Below is my code. I am adding buildfeatures in build.gradle file of app, not in the root folder.

android {
    compileSdkVersion compileSDKVer
    buildToolsVersion buildToolsVer
    defaultConfig {
        applicationId "com.sample.slothyhacker.jetpackcompose"
        minSdkVersion minSdkVer
        targetSdkVersion targetSdkVer
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

    buildFeatures {
        // Enables Jetpack Compose for this module
        //compose true
    }

    compileOptions {
        // Set both the Java and Kotlin compilers to target Java 8.
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

但是我的项目给了我一个编译错误.如果有人能指出我做错了什么,我将不胜感激.

But my project is giving me a compile error. I would really appreciate if someone can put some light on what am doing wrong.

Could not find method buildFeatures() for arguments [build_7yf57wk394cperk1t82v120yf$_run_closure1$_closure5@78c292be] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

推荐答案

你只能在 Android Studio 4.0+ 中添加这个,只有 Canary build 可用

You can add this only in Android Studio 4.0+ which is only available Canary build

这篇关于在 build.gradle 文件中添加 buildFeatures 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆