build.gradle(:app)中FeatureBuild块报错:找不到FeatureBuild()方法
问题解决建议
错误原因
你写的FeatureBuild是不存在的Gradle配置块,Android Gradle插件中用于启用构建特性的正确配置块是buildFeatures,同时ViewBinding的属性名是小写的viewBinding(不是大写开头的ViewBinding)。
修复步骤
把错误的FeatureBuild块合并到已有的buildFeatures块中,修改后的代码如下:
android { // 其他配置... buildFeatures { compose true viewBinding true // 在这里添加ViewBinding的启用配置 } // 其他配置... }
完整修改后的android块示例
android { namespace 'com.example.loginpage' compileSdk 33 defaultConfig { applicationId "com.example.loginpage" minSdk 27 targetSdk 33 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary true } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } buildFeatures { compose true viewBinding true // 合并到这里 } composeOptions { kotlinCompilerExtensionVersion '1.3.2' } packagingOptions { resources { excludes += '/META-INF/{AL2.0,LGPL2.1}' } } }
修改后同步Gradle即可解决报错。
内容的提问来源于stack exchange,提问作者Luke Jones
相关产品推荐
相关产品推荐

