diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 5c09328..6ac1271 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -8,11 +8,11 @@ jobs: if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - - uses: actions/setup-java@v3 + - uses: actions/setup-java@v4 with: distribution: "temurin" java-version: "17" @@ -36,3 +36,10 @@ jobs: cd android ./gradlew build ls -lh build/outputs/aar + + - name: Upload Android library + uses: actions/upload-artifact@v4 + with: + name: android-library + path: | + android/build/outputs/aar/ diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 7ed202f..ff4b8b3 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -1,4 +1,11 @@ +import org.gradle.tooling.BuildException import java.util.Base64 +import java.util.Properties +import kotlin.io.path.Path +import kotlin.io.path.absolutePathString +import kotlin.io.path.exists +import kotlin.io.path.listDirectoryEntries +import kotlin.io.path.name plugins { id("maven-publish") @@ -14,7 +21,41 @@ repositories { google() } +fun ndkPath(): String { + val file = project.rootProject.file("local.properties") + var androidHome = System.getenv("ANDROID_HOME") + + if (file.exists()) { + val properties = Properties() + properties.load(project.rootProject.file("local.properties").inputStream()) + + properties["sdk.dir"]?.let { + androidHome = it as String + } + } + + check(androidHome != null) { "Could not find android SDK dir" } + + val ndks = Path(androidHome).resolve("ndk") + check(ndks.exists()) { "Expected NDK installations at $ndks" } + + for (entry in ndks.listDirectoryEntries()) { + val name = entry.name + val majorVersion = name.split('.').first().toInt() + + // We want to use NDK 28 or newer to build with 16KB support by default. + if (majorVersion >= 28) { + return entry.absolutePathString() + } + } + + error("Expected an NDK 28 or later installation in $ndks") +} + val buildRust = tasks.register("buildRust") { + group = "build" + environment("ANDROID_NDK_HOME", ndkPath()) + workingDir("..") commandLine( "cargo", diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index b82aa23..ff23a68 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME