Skip to content

Commit 67cba11

Browse files
authored
Build with NDK 28 or newer for 16KB page alignment (#101)
1 parent 8cde624 commit 67cba11

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

.github/workflows/android.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ jobs:
88
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212
with:
1313
submodules: true
1414

15-
- uses: actions/setup-java@v3
15+
- uses: actions/setup-java@v4
1616
with:
1717
distribution: "temurin"
1818
java-version: "17"
@@ -36,3 +36,10 @@ jobs:
3636
cd android
3737
./gradlew build
3838
ls -lh build/outputs/aar
39+
40+
- name: Upload Android library
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: android-library
44+
path: |
45+
android/build/outputs/aar/

android/build.gradle.kts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
import org.gradle.tooling.BuildException
12
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
29

310
plugins {
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+
1755
val buildRust = tasks.register<Exec>("buildRust") {
56+
group = "build"
57+
environment("ANDROID_NDK_HOME", ndkPath())
58+
1859
workingDir("..")
1960
commandLine(
2061
"cargo",

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)