I created a simple project in AndroidStudio and added dependencies. Android Studio Hedgehog | 2023.1.1 Canary 16 Java 17.0.7 for gradle too
libs.versions.toml
[versions]
agp = "8.1.0"
kotlin = "1.8.22"
ksp = "1.9.0-1.0.13"
hilt = "2.47"
core-ktx = "1.10.1"
junit = "4.13.2"
androidx-test-ext-junit = "1.1.5"
espresso-core = "3.5.1"
appcompat = "1.6.1"
material = "1.9.0"
[libraries]
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
daggerHilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
kotlinKsp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
build.gradle.kts in project
Top-level build file where you can add configuration options common to all sub-projects/modules.
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.kotlinKsp) apply false
alias(libs.plugins.daggerHilt) apply false
}
true // Needed to make the Suppress annotation work for the plugins block
build.gradle.kts in module app
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kotlinKsp)
alias(libs.plugins.daggerHilt)
}
android {
namespace = "com.example"
compileSdk = 34
defaultConfig {
applicationId = "com.example"
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_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}
dependencies {
implementation(libs.core.ktx)
implementation(libs.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
Material3
implementation "androidx.compose.material:material:$compose_version"
implementation("androidx.compose.material:material-icons-extended-android:1.5.0")
Compose
implementation("androidx.compose.ui:ui:1.5.0")
implementation("androidx.compose.ui:ui-tooling-preview:")
debugImplementation("androidx.compose.ui:ui-tooling:1.5.0")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.5.0")
implementation("androidx.activity:activity-compose:1.7.2")
lifecycler
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1")
implementation("androidx.navigation:navigation-compose:2.7.0")
implementation("androidx.hilt:hilt-navigation-compose:1.0.0")
Tests
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.5.0")
Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
//Dagger - Hilt
implementation("androidx.hilt:hilt-android:2.47")
ksp("com.google.dagger:hilt-android-compiler:2.47")
Room Database
implementation("androidx.room:room-ktx:2.5.2")
ksp("androidx.room:room-compiler:2.5.2")
Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:2.5.2")
androidTestImplementation("androidx.room:room-testing:2.5.2")
}
settings.gradle.kts
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
>! }
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
>! }
}
>!
rootProject.name = "Example"
include(":app")
>!
gradle.properties:
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
kotlin.code.style=official
android.nonTransitiveRClass=true
gradle-wrapper.properties:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
And when synchronizing the project, an error occurs:
Unable to load class 'org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsHelper' org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsHelper Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart) Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project. In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
I tried and asked ChatGPT :)
./gradlew cleanBuildCache
But there was another error:Variant 'apiElements' capability com.android.tools.build:gradle:8.1.0 declares a library, packaged as a jar, and its dependencies declared externally:
Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
Other compatible attribute:
Doesn't say anything about org.gradle.plugin.api-version (required '8.3')
Variant 'javadocElements' capability com.android.tools.build:gradle:8.1.0 declares a component for use during runtime, and its dependencies declared externally:
Incompatible because this component declares documentation and the consumer needed a library
Other compatible attributes:
Doesn't say anything about its target Java version (required compatibility with Java 8)
Doesn't say anything about its elements (required them packaged as a jar)
Doesn't say anything about org.gradle.plugin.api-version (required '8.3')
Variant 'runtimeElements' capability com.android.tools.build:gradle:8.1.0 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
Other compatible attribute:
Doesn't say anything about org.gradle.plugin.api-version (required '8.3')
Variant 'sourcesElements' capability com.android.tools.build:gradle:8.1.0 declares a component for use during runtime, and its dependencies declared externally:
Incompatible because this component declares documentation and the consumer needed a library
Other compatible attributes:
Doesn't say anything about its target Java version (required compatibility with Java 8)
Doesn't say anything about its elements (required them packaged as a jar)
Doesn't say anything about org.gradle.plugin.api-version (required '8.3')
Also tried to downgrade gradle and agp version
cleared the gralde cache and then completely deleted the .gradle folder
Restarted Android Studio and cleared all cache.
tried to upgrade version from 1.8 to 17
Added gradle tools, mavenCenter, google dependencies
7)I searched for answers on stackoverflow, github and other sites
My problem is solved when I upgrade the kotlin version to 1.9.10
.
May be you are using old version of ksp
My problem is solved when I upgrade the ksp version to 2.0.0-1.0.22
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With