Reputation: 309
I'm learning Kotlin language and when I wanted to add navigation I followed the steps suggested by the official site but my project didn't work
the error i encountered Gradle sync failed: Cause: startup failed: build file 'C:\Users....\Desktop\AndroidStudioProjeler\NavigationKotlin\build.gradle': 13: unable to resolve class val @ line 13, column 13. val nav_version = "2.3.5" ^ 1 error
line 13 =val nav_version = "2.3.5"
plugins {
id 'com.android.application'
id 'kotlin-android'
id("androidx.navigation.safeargs")
id("androidx.navigation.safeargs.kotlin")
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.navigationkotlin"
minSdk 23
targetSdk 31
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'
}
}
dependencies {
val nav_version = "2.3.5"
// Kotlin
implementation("androidx.navigation:navigation-fragment-ktx:$nav_version")
implementation("androidx.navigation:navigation-ui-ktx:$nav_version")
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
buil.gradle
buildscript {
ext.nav_version = "2.3.5"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.3.5"
val nav_version = "2.3.5"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Upvotes: 7
Views: 6358
Reputation: 109
Just take a lower version(for example ->2.3.0)and change val to def
like a: def nav_version = "2.3.0"
Upvotes: 3
Reputation: 309
First I started a new project and then instead of defining it with "val" I defined it with "def" so =def nav_version = "2.3.0". I used 2.3.0 instead of 2.3.5 and removed the "implementation" brackets.
Upvotes: 11
Reputation: 325
in project gradle:
buildscript {
ext.kotlinVersion = '1.4.30'
ext.navigationVersion = "2.3.5"
repositories {
//...
}
dependencies {
//...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
//...
}
}
Upvotes: 0