Remzi1993

Try out Java 24 for Android

Sep 16th, 2025 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.51 KB | Source Code | 0 0
  1. /* With the latest release of AGP, Gradle and Kotlin it's now possible to use Java 24! To update AGP you also need to update Android Studio, otherwise the new AGP version wouldn't work.
  2.  
  3. With desugaring Java 24 can be used with min-sdk 26, see: https://developer.android.com/studio/write/java8-support#library-desugaring
  4.  
  5. Update the following (at least): */
  6.  
  7. // libs.versions.toml
  8. agp = "8.13.0"
  9. kotlin = "2.2.20"
  10.  
  11. // gradle-wrapper.properties
  12. distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
  13.  
  14. // build.gradle.kts (example below)
  15. plugins {
  16.     alias(libs.plugins.android.application)
  17.     alias(libs.plugins.kotlin.android)
  18.     alias(libs.plugins.kotlin.compose)
  19. }
  20.  
  21. android {
  22.     namespace = "info.remzi.madlevel2_task1"
  23.     compileSdk = 36
  24.  
  25.     defaultConfig {
  26.         applicationId = "info.remzi.madlevel2_task1"
  27.         minSdk = 26
  28.         targetSdk = 36
  29.         versionCode = 1
  30.         versionName = "1.0"
  31.  
  32.         testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
  33.     }
  34.  
  35.     buildTypes {
  36.         release {
  37.             isMinifyEnabled = true
  38.             proguardFiles(
  39.                 getDefaultProguardFile("proguard-android-optimize.txt"),
  40.                 "proguard-rules.pro"
  41.             )
  42.         }
  43.     }
  44.     compileOptions {
  45.         sourceCompatibility = JavaVersion.VERSION_24
  46.         targetCompatibility = JavaVersion.VERSION_24
  47.     }
  48.     buildFeatures {
  49.         compose = true
  50.     }
  51. }
  52.  
  53. java {
  54.     toolchain {
  55.         languageVersion.set(JavaLanguageVersion.of(24))
  56.     }
  57. }
  58.  
  59. kotlin {
  60.     compilerOptions {
  61.         jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_24)
  62.     }
  63. }
  64.  
  65. dependencies {
  66.     implementation(libs.androidx.core.ktx)
  67.     implementation(libs.androidx.lifecycle.runtime.ktx)
  68.     implementation(libs.androidx.activity.compose)
  69.     implementation(platform(libs.androidx.compose.bom))
  70.     implementation(libs.androidx.compose.ui)
  71.     implementation(libs.androidx.compose.ui.graphics)
  72.     implementation(libs.androidx.compose.ui.tooling.preview)
  73.     implementation(libs.androidx.compose.material3)
  74.     testImplementation(libs.junit)
  75.     androidTestImplementation(libs.androidx.junit)
  76.     androidTestImplementation(libs.androidx.espresso.core)
  77.     androidTestImplementation(platform(libs.androidx.compose.bom))
  78.     androidTestImplementation(libs.androidx.compose.ui.test.junit4)
  79.     debugImplementation(libs.androidx.compose.ui.tooling)
  80.     debugImplementation(libs.androidx.compose.ui.test.manifest)
  81. }
  82.  
Add Comment
Please, Sign In to add comment