Reputation: 1
I am doing projects from the book Head First Android Development. I've been able to overcome any issues I've had until this one. I've searched the internet for every answer out there, and tried different things but nothing is working.
I have no errors on my gradle build until this step. I am using Gradle version 8.7. I've changed this to other versions but still get the error.
According to the book, this is what it should need to work:
Add in Gradle Project: dependencies {
ext.nav_version = "2.3.4"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
Add in Gradle App: id 'androidx.navigation.safeargs.kotlin'
I had to use () around the implementation line for it to work.
I also couldn't use ext.nav_version, but val nav_version worked for the fragment implementation to sync properly.
But when I add the plugin and classpath line it gives me a gradle error.
I tried adding () around the classpath line but it still doesn't like the word classpath (stays red underlined unless it can import this at the top of my gradle:
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.UnknownSnapshot.classpath
It also doesn't like the '' on the plugin, so I used ("") instead.
This is the error I am consistently getting no matter what I try
Build file Plugin [id: 'androidx.navigation.safeargs.kotlin'] was not found in any of the following sources:
I feel stupid but I need help to get past this error. This is the first time I wasn't able to figure it out on my own and it seems like it should be easy to add this.
Here is my entire gradle file:
// I've added the buildscript code from recommendations in other posts here with the dependency but it didn't work.
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.UnknownSnapshot.classpath // I've tried it with and without this part. It adds this if I import the classpath from the dependencies line.
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
} // I've tried adding the plugin here as well as in the gradle app file but it didn't help, and I've also tried just having it here and not in the gradle app, but that didn't fix it either.
android {
namespace = "com.example.secretmessaage"
compileSdk = 34
defaultConfig {
applicationId = "com.example.secretmessaage"
minSdk = 24
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"
}
//I tried adding the buildscript code from other posts here too but it didn't work.
}
dependencies {
val nav_version = "2.3.4" //I've tried different versions here and also removed this and tried it with the version hardcoded in the implementation and plugin lines.
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
implementation ("androidx.navigation:navigation-fragment-ktx:$nav_version") //I had no errors up to this point, it's only when I added the classpath below that it gives me errors.
classpath ("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version") // It doesn't like classpath and forces the import to get past that error.
}
This is my Gradle App file:
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
id ("androidx.navigation.safeargs") //I've tried with and without .kotlin, apply false at the end, and with alias and apply instead of id.
}
My stuff is all on my C drive, not external hard drive.
I have android.useAndroidX=true in my properties gradle. (it was already there, so I didn't have to change this).
I've added the plugin and dependencies lines with variations of (""), (''), "", and ''. Also tried with and without .kotlin, apply false).
I've tried adding the buildscript code, at the top and bottom of my gradle file per other post recommendations.
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.3.4"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
I've tried different versions of the safeargs (the one the book uses is 2.3.5, the one Android Studio suggested was 2.8.3, I've also tried all of the other ones I've found in posts online about this issue).
I've tried the android docs and every post that I can find about this, here's examples:
https://developer.android.com/guide/navigation/use-graph/safe-args#kts
I have tried clearing cache, rebuilding and clean project multiple times.
Nothing is working. This is very frustrating.
Upvotes: 0
Views: 126