Home > database >  The id I am trying to add to use navigation in Kotlin gives an error
The id I am trying to add to use navigation in Kotlin gives an error

Time:02-10

enter image description here

Definitions included in the Build Gradle Module

 plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android-extensions'
    id("androidx.navigation.safeargs.kotlin")
    }

    android {
        compileSdk 32

    defaultConfig {
        applicationId "com.project.sunpanel"
        minSdk 23
        targetSdk 32
        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
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding = true
    }


    def  nav_version = "2.4.0"
    dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.4.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation("androidx.navigation:navigation-fragment-ktx:$nav_version")
    implementation("androidx.navigation:navigation-ui-ktx:$nav_version")

Definitions included in the Build Gradle Project

buildscript {
    ext.kotlin_version = "1.6.10"
    repositories {
        google()
        mavenCentral()
    }
        dependencies {
        classpath "com.android.tools.build:gradle:7.1.1"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

            def nav_version = "2.4.0"
            classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
        }

}

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

The error I get is as follows;

Exception is: org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'androidx.navigation.safeargs.kotlin'] was not found in any of the following sources:

  • Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
  • Plugin Repositories (plugin dependency must include a version number for this source
  • Unable to load class 'com.android.build.api.extension.AndroidComponentsExtension'. This is an unexpected error. Please file a bug containing the idea.log file.

CodePudding user response:

Your project level build file is missing the allprojects -> repositories block.

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
  • Related