Skip to content

Commit 87f5dab

Browse files
committed
Add androidTarget to runtime module
OA# pick ccf3b6f Research android target support
1 parent 2282f90 commit 87f5dab

File tree

6 files changed

+140
-4
lines changed

6 files changed

+140
-4
lines changed

examples/kotlin-multiplatform/build.gradle

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import kotlinx.benchmark.gradle.JsBenchmarksExecutor
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23

34
plugins {
45
id 'org.jetbrains.kotlin.multiplatform'
@@ -27,6 +28,8 @@ android {
2728

2829
buildTypes {
2930
release {
31+
// isMinifyEnabled = false
32+
// proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
3033
}
3134
}
3235
compileOptions {
@@ -35,7 +38,18 @@ android {
3538
}
3639
}
3740

41+
// Could not determine the dependencies of task ':examples:kotlin-multiplatform:extractReleaseAnnotations'.
42+
// > Could not resolve all task dependencies for configuration ':examples:kotlin-multiplatform:detachedConfiguration1'.
43+
// > Could not find com.android.tools.lint:lint-gradle:31.2.2.
44+
repositories {
45+
google()
46+
}
47+
3848
kotlin {
49+
androidTarget {
50+
// Android target does not have any compilations
51+
println("android compilations: ${compilations.size()}")
52+
}
3953
jvm {
4054
compilations.create('benchmark') { associateWith(compilations.main) }
4155
}
@@ -52,8 +66,6 @@ kotlin {
5266
linuxX64()
5367
mingwX64()
5468

55-
androidTarget {}
56-
5769
applyDefaultHierarchyTemplate()
5870

5971
targets.configureEach {
@@ -86,7 +98,19 @@ kotlin {
8698

8799
nativeMain {}
88100

89-
androidMain {}
101+
androidMain {
102+
kotlin.setSrcDirs(["src/androidMain/kotlin"])
103+
}
104+
105+
forEach {
106+
// Android target has 3 source sets: androidMain, androidUnitTest, and androidInstrumentedTest
107+
println("SourceSet: $it")
108+
println(it.name)
109+
println(it.kotlin)
110+
println(it.kotlin.srcDirs)
111+
println(it.kotlin.sourceDirectories)
112+
}
113+
90114
}
91115
}
92116

@@ -164,3 +188,14 @@ benchmark {
164188
register("android")
165189
}
166190
}
191+
192+
java {
193+
sourceCompatibility = JavaVersion.VERSION_1_8
194+
targetCompatibility = JavaVersion.VERSION_1_8
195+
}
196+
197+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
198+
compilerOptions {
199+
jvmTarget.set(JvmTarget.JVM_1_8)
200+
}
201+
}

plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,4 @@ if (project.findProperty("publication_repository") == "space") {
168168

169169
apiValidation {
170170
nonPublicMarkers += listOf("kotlinx.benchmark.gradle.internal.KotlinxBenchmarkPluginInternalApi")
171-
}
171+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package kotlinx.benchmark
2+
3+
actual enum class Scope {
4+
Benchmark
5+
}
6+
7+
@Target(AnnotationTarget.CLASS)
8+
actual annotation class State(actual val value: Scope)
9+
10+
@Target(AnnotationTarget.FUNCTION)
11+
actual annotation class Setup
12+
13+
@Target(AnnotationTarget.FUNCTION)
14+
actual annotation class TearDown
15+
16+
@Target(AnnotationTarget.FUNCTION)
17+
actual annotation class Benchmark
18+
19+
20+
@Target(AnnotationTarget.CLASS)
21+
actual annotation class BenchmarkMode(actual vararg val value: Mode)
22+
23+
actual enum class Mode {
24+
Throughput, AverageTime
25+
}
26+
27+
@Target(AnnotationTarget.CLASS)
28+
actual annotation class OutputTimeUnit(actual val value: BenchmarkTimeUnit)
29+
30+
actual enum class BenchmarkTimeUnit {
31+
NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES
32+
}
33+
34+
@Target(AnnotationTarget.CLASS)
35+
actual annotation class Warmup(
36+
actual val iterations: Int,
37+
actual val time: Int,
38+
actual val timeUnit: BenchmarkTimeUnit,
39+
actual val batchSize: Int
40+
)
41+
42+
@Target(AnnotationTarget.CLASS)
43+
actual annotation class Measurement(
44+
actual val iterations: Int,
45+
actual val time: Int,
46+
actual val timeUnit: BenchmarkTimeUnit,
47+
actual val batchSize: Int
48+
)
49+
50+
actual annotation class Param(actual vararg val value: String)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package kotlinx.benchmark
2+
3+
4+
internal actual fun Double.format(precision: Int, useGrouping: Boolean): String =
5+
error("Not implemented")
6+
7+
internal actual fun String.writeFile(text: String): Unit =
8+
error("Not implemented")
9+
10+
internal actual fun String.readFile(): String =
11+
error("Not implemented")
12+
13+
internal actual inline fun measureNanoseconds(block: () -> Unit): Long =
14+
error("Not implemented")

runtime/build.gradle.kts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
34
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
45
import java.util.*
56

67
plugins {
78
alias(libs.plugins.kotlin.multiplatform)
9+
id("com.android.library")
810
}
911

1012
repositories {
1113
mavenCentral()
1214
}
1315

16+
android {
17+
compileSdk = 34
18+
namespace = "org.jetbrains.kotlinx.examples"
19+
20+
defaultConfig {
21+
minSdk = 29
22+
targetSdk = 34
23+
24+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
25+
}
26+
27+
buildTypes {
28+
release {
29+
}
30+
}
31+
compileOptions {
32+
sourceCompatibility = JavaVersion.VERSION_1_8
33+
targetCompatibility = JavaVersion.VERSION_1_8
34+
}
35+
}
36+
1437
kotlin {
1538
// According to https://kotlinlang.org/docs/native-target-support.html
1639

@@ -45,12 +68,15 @@ kotlin {
4568
@OptIn(ExperimentalWasmDsl::class)
4669
wasm("wasmJs") { d8() }
4770

71+
androidTarget {}
72+
4873
@OptIn(ExperimentalKotlinGradlePluginApi::class)
4974
applyDefaultHierarchyTemplate {
5075
common {
5176
group("jsWasmJsShared") {
5277
withJs()
5378
withWasmJs()
79+
withAndroidTarget()
5480
}
5581
}
5682
}
@@ -125,3 +151,14 @@ tasks.withType(KotlinNativeCompile::class).configureEach {
125151
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
126152
)
127153
}
154+
155+
java {
156+
sourceCompatibility = JavaVersion.VERSION_1_8
157+
targetCompatibility = JavaVersion.VERSION_1_8
158+
}
159+
160+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).configureEach {
161+
compilerOptions {
162+
jvmTarget.set(JvmTarget.JVM_1_8)
163+
}
164+
}

0 commit comments

Comments
 (0)