Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when adding buildFeatures in build.gradle file

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. 
like image 877
Sreedev Avatar asked Nov 04 '19 11:11

Sreedev


1 Answers

I caught this error when I tried to add Jetpack to my existing app. I followed Suraj's answer, even used the newest Kotlin gradle plugin, and couldn't exactly figure out what was wrong. I also followed the official setup guide and it didn't work. Everything seemed okay, but nothing helped.

Installing Android Studio 4.0 canary didn't help either.

Turns out, it's not enough to just include certain dependencies – you need specific versions or higher. I was using an older Android Gradle plugin: 3.5.3. Upgrading to 4.0.0-alpha07 fixed the error:

classpath 'com.android.tools.build:gradle:4.0.0-alpha07' 

Make sure to check your dependencies if you're adding Jetpack to an existing app

like image 67
Morozzzko Avatar answered Sep 21 '22 18:09

Morozzzko