I am giving the Navigation option a try and must say that so far…..does not make me happy.
It is almost like this is some alpha version of a new feature so many bugs as it has.
Besides the problem you can read al over de place of studio not generating the Directions-classes and how to fix this (clean project + rebuild or invalidate caches) or (remove stuff from gradle -> sync -> re-add) which works by the way, i have a different problem.
When i finally get al the directions-classes to work correctly and i press the run button to test my app in the emulator, all directions-classes seem to be lost.
result: error’s in all my fragments.
I read and tried all but 1 option in this post: stackoverflow post
the 1 option i could not try i the one where the add the path in the gradle:
sourceSets {
getByName("main") {
java.srcDirs("build/generated/source/navigation-args")
} }
For the simple reason then when i do, i get and error “sourceset with name ‘main’ not found.”
and i have no idea how to solve this.
On the other hand i lost the hope that this is the actual solution to my problem.
below i am posting by 2 gradle files in the hope i made a really stupid misstake then (in which case i owe google a apology for complaining)
module: app
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
id("androidx.navigation.safeargs")
}
android {
namespace = "com.example.tripmemory"
compileSdk = 34
defaultConfig {
applicationId = "com.example.tripmemory"
minSdk = 28
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = 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
}
}
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)
implementation("androidx.navigation:navigation-dynamic-features-fragment:2.7.7")
implementation(libs.androidx.preference.ktx)
implementation(libs.androidx.room.common)
implementation(libs.androidx.room.ktx)
implementation(libs.play.services.maps)
implementation("com.google.android.gms:play-services-location:21.2.0")
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}
and the project gradle
buildscript {
dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7")
}
}
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") version("2.0.1") apply false
}
and to be complete: the libs.version
[versions]
agp = "8.4.1"
kotlin = "1.9.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.12.0"
constraintlayout = "2.1.4"
navigationFragmentKtx = "2.7.7"
navigationUiKtx = "2.7.7"
playServicesLocation = "21.2.0"
preferenceKtx = "1.2.1"
roomCommon = "2.6.1"
playServicesMaps = "18.2.0"
roomKtx = "2.6.1"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
androidx-navigation-fragment-ktx = { group = "androidx.navigation", name = "navigation-fragment-ktx", version.ref = "navigationFragmentKtx" }
androidx-navigation-ui-ktx = { group = "androidx.navigation", name = "navigation-ui-ktx", version.ref = "navigationUiKtx" }
androidx-preference-ktx = { group = "androidx.preference", name = "preference-ktx", version.ref = "preferenceKtx" }
androidx-room-common = { group = "androidx.room", name = "room-common", version.ref = "roomCommon" }
play-services-location = { module = "com.google.android.gms:play-services-location", version.ref = "playServicesLocation" }
play-services-maps = { group = "com.google.android.gms", name = "play-services-maps", version.ref = "playServicesMaps" }
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "roomKtx" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
I hope somebody knows how to solve this problem because i like the navigation way of working but at the moment the benefits are disapearing fast.