1+ import org.gradle.tooling.BuildException
12import java.util.Base64
3+ import java.util.Properties
4+ import kotlin.io.path.Path
5+ import kotlin.io.path.absolutePathString
6+ import kotlin.io.path.exists
7+ import kotlin.io.path.listDirectoryEntries
8+ import kotlin.io.path.name
29
310plugins {
411 id(" maven-publish" )
@@ -14,7 +21,41 @@ repositories {
1421 google()
1522}
1623
24+ fun ndkPath (): String {
25+ val file = project.rootProject.file(" local.properties" )
26+ var androidHome = System .getenv(" ANDROID_HOME" )
27+
28+ if (file.exists()) {
29+ val properties = Properties ()
30+ properties.load(project.rootProject.file(" local.properties" ).inputStream())
31+
32+ properties[" sdk.dir" ]?.let {
33+ androidHome = it as String
34+ }
35+ }
36+
37+ check(androidHome != null ) { " Could not find android SDK dir" }
38+
39+ val ndks = Path (androidHome).resolve(" ndk" )
40+ check(ndks.exists()) { " Expected NDK installations at $ndks " }
41+
42+ for (entry in ndks.listDirectoryEntries()) {
43+ val name = entry.name
44+ val majorVersion = name.split(' .' ).first().toInt()
45+
46+ // We want to use NDK 28 or newer to build with 16KB support by default.
47+ if (majorVersion >= 28 ) {
48+ return entry.absolutePathString()
49+ }
50+ }
51+
52+ error(" Expected an NDK 28 or later installation in $ndks " )
53+ }
54+
1755val buildRust = tasks.register<Exec >(" buildRust" ) {
56+ group = " build"
57+ environment(" ANDROID_NDK_HOME" , ndkPath())
58+
1859 workingDir(" .." )
1960 commandLine(
2061 " cargo" ,
0 commit comments