I want to use Kotlin Extensions in my Android project, but from what I see, it's deprecated feature. I try to use 1.7.0 Kotlin version in my Android project. In addition to downgrading this version, I also changed the AGP version to 7.4.1. What additional configuration do I need? Here are my project files:
build.gradle.kts (root):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose) apply false
}
build.gradle.kts (app):
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}
android {
namespace = "com.example.selfpromoapp"
compileSdk = 34
defaultConfig {
applicationId = "com.example.selfpromoapp"
minSdk = 21
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 = VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "11"
}
buildFeatures {
compose = true
}
}
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.material)
testImplementation(libs.junit)
implementation(libs.androidx.appcompat)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
libs.versions.toml:
[versions]
agp = "7.4.1"
appcompat = "1.7.0"
kotlin = "1.7.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
lifecycleRuntimeKtx = "2.8.6"
activityCompose = "1.9.3"
composeBom = "2024.04.01"
material = "1.12.0"
[libraries]
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
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-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
material = { module = "com.google.android.material:material", version.ref = "material" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
I do not know what you mean by "Kotlin Extensions" (maybe the Kotlin Android Extensions from synthetics, the predecessor of view bindings which is the predecessor of Compose?) or why its deprecation leads you to revert back to an ancient Kotlin version (1.7.0 was released mid 2022), but if you insinst to do so you can.
The most important part is to revert the changes made in Kotlin 2.0.0 to how the Compose compiler is used:
Remove the plugin kotlin-compose
from the version catalog and the associated entry in the plugin block of your gradle files.
In the app level gradle file add this to the android
block instead:
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0"
}
The Compose compiler's version is linked to the Kotlin version so you won't be able to update this version as long as you stay on Kotlin 1.7.0. You will be able to use a newer Compose BOM though, although I'm not sure about the incompatibilities that may arise over time or how they will manifest.
And finally, I do not know why you downgraded the AGP version to 7.4.1, but you most likely need to increase it again for a successful build. Using Android Studio Ladybug | 2024.2.1 Patch 2 the newest version 8.7.2
worked fine for me.
As a closing note I want to stress again how useless this exercise seems to deliberately stay on such an old Kotlin version. Whatever you think the reasons are why you need to do this, I would strongly advise you to reconsider.