Skip to content

Commit

Permalink
Support users to set sdkDir for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
kx412764776 committed Sep 13, 2024
1 parent 5874eee commit 66252c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ private fun Project.createSetupAndroidProjectTask(target: AndroidBenchmarkTarget
)
it.writeText(newText)
}

generatedAndroidProjectDir.resolve("local.properties").let {
val sdkPath = target.sdkDir.orNull
if (sdkPath.isNullOrBlank()) {
throw GradleException("Android SDK path is not set. Please set ANDROID_HOME environment variable or specify sdkPath in the build script.")
} else {
it.writeText("sdk.dir=${sdkPath.replace("\\", "/")}\n")
logger.info("SDK path written to local.properties: ${it.readText()}")
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kotlinx.benchmark.gradle

import kotlinx.benchmark.gradle.internal.KotlinxBenchmarkPluginInternalApi
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
Expand Down Expand Up @@ -134,5 +135,9 @@ class AndroidBenchmarkTarget
constructor(
extension: BenchmarksExtension,
name: String,
val target: KotlinAndroidTarget
) : BenchmarkTarget(extension, name)
val target: KotlinAndroidTarget,
) : BenchmarkTarget(extension, name) {
val sdkDir: Property<String> = extension.project.objects.property(String::class.java).convention(
System.getenv("ANDROID_HOME") ?: ""
)
}

0 comments on commit 66252c6

Please sign in to comment.