diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 60bfea6c8..63f87cc55 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -19,6 +19,7 @@ tasks.withType().configureEach { dependencies { compileOnly(libs.android.gradlePlugin) + compileOnly(libs.kotlin.gradlePlugin) } gradlePlugin { @@ -27,5 +28,9 @@ gradlePlugin { id = "ndksamples.android.application" implementationClass = "com.android.ndk.samples.buildlogic.AndroidApplicationConventionPlugin" } + register("kotlinAndroid") { + id = "ndksamples.android.kotlin" + implementationClass = "com.android.ndk.samples.buildlogic.KotlinConventionPlugin" + } } } diff --git a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt index 8997bfc2d..23f521823 100644 --- a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt +++ b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt @@ -20,6 +20,10 @@ class AndroidApplicationConventionPlugin : Plugin { minSdk = Versions.MIN_SDK targetSdk = Versions.TARGET_SDK } + compileOptions { + sourceCompatibility = Versions.JAVA + targetCompatibility = Versions.JAVA + } } } } diff --git a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/KotlinConventionPlugin.kt b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/KotlinConventionPlugin.kt new file mode 100644 index 000000000..4b031da8c --- /dev/null +++ b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/KotlinConventionPlugin.kt @@ -0,0 +1,27 @@ +package com.android.ndk.samples.buildlogic + +import com.android.build.api.dsl.ApplicationExtension + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +class KotlinConventionPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + with(pluginManager) { + apply("org.jetbrains.kotlin.android") + } + + extensions.configure { + tasks.withType().configureEach { + kotlinOptions { + jvmTarget = Versions.JAVA.toString() + } + } + } + } + } +} diff --git a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/Versions.kt b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/Versions.kt index 068504756..3d4898a4a 100644 --- a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/Versions.kt +++ b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/Versions.kt @@ -1,8 +1,11 @@ package com.android.ndk.samples.buildlogic +import org.gradle.api.JavaVersion + object Versions { const val COMPILE_SDK = 34 const val TARGET_SDK = 34 const val MIN_SDK = 21 const val NDK = "26.3.11579264" // r26d + val JAVA = JavaVersion.VERSION_1_8 } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 736618e5a..0c12d7450 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,6 +14,7 @@ ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitV espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } material = { group = "com.google.android.material", name = "material", version.ref = "material" } +kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" } # build-logic dependencies android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }