The new Kotlin gradle system (e.g. build.gradle.kts), look for the version catalog file named libs.versions.toml file with gradle version field under [versions] section and update with the required version.
[versions]
androidGradlePlugin = "8.7.0"
androidxCore = "1.15.0"
androidxLifecycle = "2.8.7"