1
+ import org.gradle.tooling.BuildException
1
2
import 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
2
9
3
10
plugins {
4
11
id(" maven-publish" )
@@ -14,7 +21,41 @@ repositories {
14
21
google()
15
22
}
16
23
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
+
17
55
val buildRust = tasks.register<Exec >(" buildRust" ) {
56
+ group = " build"
57
+ environment(" ANDROID_NDK_HOME" , ndkPath())
58
+
18
59
workingDir(" .." )
19
60
commandLine(
20
61
" cargo" ,
0 commit comments