1

recently I had some problems with the gradle files so i made few adjustments to solve these problems and every adjustment led to a new error ,the current one is :
Could not find method classpath() for arguments [com.android.tools.build:gradle:4.1.3] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

this is the gradle>build.gradle file:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"
        //classpath "com.android.tools.build:gradle:+"
        classpath 'com.google.gms:google-services:4.2.0'

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

and this is the app>src>build.gradle file:

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.myapplication_10"
        minSdkVersion 29
        targetSdkVersion 29
        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
    }
}

dependencies {
    classpath "com.android.tools.build:gradle:4.1.3"
    //classpath 'com.android.tools.build:gradle:+'
    classpath 'com.google.gms:google-services:4.2.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

And I changed the gradle version in "gradel-wrapper" file :

#Tue Mar 23 14:02:06 EET 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip

the gradle 4.1.3 in the first two files is the default value and I tried to change it to 6.8.2 (as in the gradle-wrapper file) but it throws an error.

2 Answers 2

4

In your app/build.gradle remove the classpath statements

dependencies {
    //classpath "com.android.tools.build:gradle:4.1.3"
    //classpath 'com.android.tools.build:gradle:+'
    //classpath 'com.google.gms:google-services:4.2.0'

    implementation 'androidx.appcompat:appcompat:1.1.0'
    ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much it works! but in the future when I make new application should i do anything? like use the same gradle files? or this is a permanent solution?
@MahmoudِِِAkhras Each application has own build.gradle. The content depends by what your are going to achieve. some app could require other dependencies for example.
1

Ok I think in your Appgradle file you have called classpath. It should be only added in Gradle file, not in-app Gradle file

dependencies {

//Remove these class path you will be good to go
classpath "com.android.tools.build:gradle:4.1.3"
//classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:4.2.0'


implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.