2

I made some search before posting here. I created a new project and I have the below:

From:(build gradle project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
}

To:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
}
dependencies {
    // Import the Firebase BoM
    implementation platform('com.google.firebase:firebase-bom:31.3.0')


    // TODO: Add the dependencies for Firebase products you want to use
    // When using the BoM, don't specify versions in Firebase dependencies
    // https://firebase.google.com/docs/android/setup#available-libraries
}

So I got this error:

Could not find method implementation() for arguments [DefaultExternalModuleDependency{group='com.google.firebase', name='firebase-bom', version='31.3.0', configuration='default'}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

this is gradle app

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.delivery1'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.delivery1"
        minSdk 25
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
    implementation 'androidx.navigation:navigation-fragment:2.5.3'
    implementation 'androidx.navigation:navigation-ui:2.5.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
    classpath 'com.google.gms:google-services:4.3.15'
}
Olivier
  • 13,283
  • 1
  • 8
  • 24
Baalback
  • 387
  • 7
  • 20

2 Answers2

3

The implementation you use within dependencies { ... } actually is a configuration. This configuration needs to be added by some plugin you apply, as by default no configurations are present in a Gradle build. Language plugins like java, or kotlin("jvm"), com.android.application, (or plugins they apply transitively), add such configurations to which you can then add dependencies.

In the root project build script you showed, you do not apply any plugin, so there is also no configuration present to which you could add dependencies and thus you get a complaint by gradle, that implementation does not exist.

You probably wanted to add this line to your application-level build script instead.

Vampire
  • 35,631
  • 4
  • 76
  • 102
0

As explained here, the dependency should be added to the app gradle script, not the project script.

Olivier
  • 13,283
  • 1
  • 8
  • 24