Home > other >  Could not find method classpath() for arguments in build.gradle
Could not find method classpath() for arguments in build.gradle

Time:05-24

Hello everyone) i am making a small android app about the weather on kotlin. And I have this problem, changing the classpath does not give anything.

Problem

  • Could not find method classpath() for arguments [android.arch.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha02] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler*

build.gradle(project)

plugins {
    id 'com.android.application' version '7.2.0' apply false
    id 'com.android.library' version '7.2.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}

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

dependencies {
    classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha02"
}

build.gradle(app)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: "kotlin-kapt"

apply plugin: 'androidx.navigation.safeargs'

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.kevychsolutionstest"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    androidExtensions {
        experimental = 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'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.4.1'

    // Navigation
    implementation "android.arch.navigation:navigation-fragment:$navigation_version"
    implementation "android.arch.navigation:navigation-ui:$navigation_version"
    implementation "android.arch.navigation:navigation-fragment-ktx:$navigation_version"
    implementation "android.arch.navigation:navigation-ui-ktx:$navigation_version"

    implementation "androidx.core:core-ktx:1.7.0"
    implementation "androidx.constraintlayout:constraintlayout:2.1.3"

    // Room
    implementation "androidx.room:room-runtime:$room_version"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
    kapt "androidx.room:room-compiler:$room_version"

    // Gson
    implementation "com.google.code.gson:gson:2.8.9"

    // Kotlin Android Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"

    // Retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'

    // ViewModel
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

    // Kodein
    implementation "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
    implementation "org.kodein.di:kodein-di-framework-android-x:$kodein_version"

    // Better dateTime-time support even on older Android versions
    implementation "com.jakewharton.threetenabp:threetenabp:1.1.0"

    // Glide
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    kapt 'com.github.bumptech.glide:compiler:4.8.0'

    // Groupie RecyclerView
    implementation 'com.xwray:groupie:2.1.0'
    implementation 'com.xwray:groupie-kotlin-android-extensions:2.1.0'

    // Preference
    implementation "androidx.preference:preference:1.2.0"

    // WeatherLocation
    implementation "com.google.android.gms:play-services-location:19.0.1"

    // New Material Design
    implementation "com.google.android.material:material:1.6.0"

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0-alpha06'
}

CodePudding user response:

update the Safe args "classpath" to

 val nav_version = "2.4.2"
    classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")

instead of

    classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha02"

CodePudding user response:

Add a buildscript group to the top of the build.gradle(Project) file.

buildscript {
dependencies {
    classpath("androidx.navigation.safeargs:androidx.navigation.safeargs.gradle.plugin:2.4.1")
   }
}

Then add the plugin ID to the plugins group in the build.gradle(Module) file.

id 'androidx.navigation.safeargs'

It can help to

  • Related