I would like to use safeargs in Android for navigation. Unfortunately I always get an error from the grandle files telling "Could not get unknown property 'nav_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler".
Actually I think the problem might be because of mixing Java and Kotlin? There were some kotlin files that I converted into Java but I received this error message when inserting the arguments for the safeargs in the build.gradle file. So actually I don't need any Kotlin related stuff anymore in the build.grandl files and I tried to remove them but then I receivede the same error messages. Do you know how I can solve this problem?
Here are my build.gradle files:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.10"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here the second one:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
apply plugin: "androidx.navigation.safeargs"
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.nikhiljain.canvasdrawingsample"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
viewBinding {
enabled = true
}
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 {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4. '
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
}
CodePudding user response:
I think you need to add this just below this line ext.kotlin_version = "1.4.10"
ext.nav_version = "2.3.5"
where 2.3.5 is the desired version , but am not pretty sure about this .
and am not sure that you posted the whole gradle file , but you missing this with the part you posted .
the same way you used ext.kotlin_version = "1.4.10"
and then in dependency section you called
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
its totally equal too
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10"
You can also do it like this
buildscript {
repositories {
google()
}
dependencies {
val nav_version = "2.3.5"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
or just remove all the $kotlin_version
in your build.gradle and replace with 2.3.5 for example .