Home > Back-end >  Android studio Bumblebee build.gradle root project can't add classpath dependencies
Android studio Bumblebee build.gradle root project can't add classpath dependencies

Time:02-01

I'm trying to implement dagger-hilt in my new project but I see some differences in the new Android studio version (Bumblebee 2021.1.1):

buildscript {
    ext {
        compose_version = '1.0.5'
        hilt_version = '2.40.5'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.

plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false

}
dependencies {
    classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'
}    

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

When I try to implement hilt and the dependency block with classpath it tells me:

 Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method classpath() for arguments [com.google.dagger:hilt-android-gradle-plugin:2.40.5] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
        }

CodePudding user response:

Resolved by adding the depencies{} block into the buildScript block :

buildscript {
    ext {
        compose_version = '1.0.5'
        hilt_version = '2.40.5'
    }

    dependencies {
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'
        classpath 'com.google.gms:google-services:4.3.10'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.

plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false

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