Skip to content

Add Android native artifacts and CI coverage#148

Closed
subham8907 wants to merge 1 commit into
bonede:mainfrom
subham8907:codex/android-native-ci-squashed
Closed

Add Android native artifacts and CI coverage#148
subham8907 wants to merge 1 commit into
bonede:mainfrom
subham8907:codex/android-native-ci-squashed

Conversation

@subham8907

@subham8907 subham8907 commented May 9, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds checked-in Android native artifacts for the core tree-sitter library and the grammar packages used by downstream Android consumers, while keeping the existing desktop/native artifacts current for those refreshed modules.

It also adjusts the Gradle build so regular tests consume the checked-in native libraries instead of rebuilding native code, while CI explicitly compiles native artifacts for every grammar project.

What changed

  • Added aarch64-linux-android shared libraries for:
    • tree-sitter
    • tree-sitter-css
    • tree-sitter-go
    • tree-sitter-html
    • tree-sitter-java
    • tree-sitter-javascript
    • tree-sitter-json
    • tree-sitter-python
    • tree-sitter-typescript
  • Refreshed the existing checked-in native artifacts for Linux, macOS, and Windows for the same modules so the committed artifacts match the current build output.
  • Updated Android runtime loading in NativeUtils:
    • Detects Android/Dalvik runtime.
    • Uses System.loadLibrary(...) on Android instead of extracting and loading the resource path manually.
    • Keeps the existing resource extraction/loading behavior for desktop JVMs.
  • Changed JNI_OnLoad from JNI_VERSION_10 to JNI_VERSION_1_6 so the native library can load on Android runtimes that do not accept the newer JNI version.
  • Updated the native build helpers:
    • Uses Gradle provider-backed exec APIs where needed.
    • Checks the default macOS Android SDK path at ~/Library/Android/sdk when Android SDK environment variables are not set.
    • Keeps Android NDK discovery compatible with ANDROID_NDK_HOME, ANDROID_NDK_ROOT, ANDROID_HOME, and ANDROID_SDK_ROOT.
  • Fixed tree-sitter-ocaml:buildNative by pointing it at the OCaml grammar source layout under grammars/ocaml/src.
  • Updated task registration in build.gradle:
    • Registers downloadSource and buildNative only for projects that define libVersion.
    • Keeps grammar tests dependent on downloaded parser sources.
    • Avoids wiring processResources/tests to buildNative, so ./gradlew test does not unexpectedly rebuild native artifacts.
  • Updated GitHub Actions:
    • Replaces the broad OS test matrix with an explicit native-artifact build matrix.
    • Runs ./gradlew buildNative so every grammar project's native task is compiled for each configured desktop target.
    • Runs ./gradlew buildNative -PtreeSitterTargets=aarch64-linux-android in the Android job so Android native compilation also covers all grammar projects.

Why

Android consumers need packaged native grammar libraries, but the desktop JVM loading path is not appropriate for Android. Android expects libraries to be loaded through the platform linker with System.loadLibrary, and the JNI version returned by JNI_OnLoad must be compatible with Android.

The test/build wiring also needed to avoid rebuilding native libraries during normal test runs. Native compilation is now exercised deliberately by CI through buildNative, while ./gradlew test remains focused on tests and uses the checked-in resources.

Validation

  • ./gradlew :tree-sitter-ocaml:buildNative -PtreeSitterTargets=aarch64-macos --stacktrace
  • ./gradlew buildNative -PtreeSitterTargets=aarch64-macos --stacktrace
  • ./gradlew :tree-sitter-ocaml:test --stacktrace
  • ./gradlew test --stacktrace

@subham8907
subham8907 force-pushed the codex/android-native-ci-squashed branch from 3f0535e to d90ba5c Compare May 9, 2026 12:24
@subham8907

Copy link
Copy Markdown
Contributor Author

Recreated from renamed branch: #149

@subham8907 subham8907 closed this May 9, 2026
@subham8907
subham8907 deleted the codex/android-native-ci-squashed branch May 9, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant