Skip to content

Add Android native artifacts and CI coverage#150

Closed
subham8907 wants to merge 2 commits into
bonede:mainfrom
subham8907:android-native-grammer
Closed

Add Android native artifacts and CI coverage#150
subham8907 wants to merge 2 commits into
bonede:mainfrom
subham8907:android-native-grammer

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 every grammar package, while keeping the existing desktop/native artifacts current for the previously 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.

Finally, it adds explicit third-party license notices for the bundled OpenJDK 11 JNI headers, Gradle wrapper files, and Unicode ConvertUTF sources.

What changed

  • Added aarch64-linux-android shared libraries for the core tree-sitter module and every grammar module in this repository.
  • 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.
    • Reuses an existing Zig binary and verifies each downloaded Zig mirror archive before accepting it.
    • 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.
  • Added third-party notice files:
    • THIRD_PARTY_NOTICES.md
    • OpenJDK 11 LICENSE and ADDITIONAL_LICENSE_INFO under third_party_licenses/openjdk-11
    • Gradle license under third_party_licenses/gradle
    • Full Apache License 2.0 text under third_party_licenses/apache-2.0
    • Unicode license under third_party_licenses/unicode
    • Zig license under third_party_licenses/zig
    • tree-sitter core license under third_party_licenses/tree-sitter-core
    • tree-sitter core bundled Unicode license under third_party_licenses/tree-sitter-core/lib-src-unicode
    • Grammar source licenses under third_party_licenses/grammars/<grammar-project>/LICENSE
  • Checked bundled headers and Unicode-related native sources:
    • All headers under include/jni carry OpenJDK GPLv2/classpath markers.
    • Unicode source usage is limited to tree-sitter/src/main/c/ConvertUTF.c, ConvertUTF.h, the related readme.txt, and calls from org_treesitter_TSParser.c.

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 repository already vendors OpenJDK JNI headers, Gradle wrapper files, and Unicode conversion sources, so this PR also adds the corresponding license texts and a notice index.

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
  • git diff --check
  • Header/license scan with rg for OpenJDK GPL/classpath markers and Unicode native source usage

@subham8907
subham8907 marked this pull request as ready for review May 9, 2026 12:30
@subham8907

Copy link
Copy Markdown
Contributor Author

@bonede now binder and grammer fully compatible with android please merge i need this for my project
Screenshot_2026-05-09-18-02-42-78_0db6b82853352d7ff97fd26470a1b19d

Screenshot_2026-05-09-18-02-35-29_0db6b82853352d7ff97fd26470a1b19d w

@subham8907
subham8907 force-pushed the android-native-grammer branch 7 times, most recently from b790387 to 33fc91a Compare May 10, 2026 01:44
Add Android native library loading support, checked-in Android artifacts, all-grammar native CI coverage, source download retry handling, and third-party license notices for bundled native dependencies.
@subham8907
subham8907 force-pushed the android-native-grammer branch from 33fc91a to e1ef550 Compare May 10, 2026 03:33
bonede

This comment was marked as off-topic.

@bonede

bonede commented May 16, 2026

Copy link
Copy Markdown
Owner

Sorry, huge PR with AI generated content will not be merged. It's too much to review.

@bonede bonede closed this May 16, 2026
@subham8907

Copy link
Copy Markdown
Contributor Author

Sorry, huge PR with AI generated content will not be merged. It's too much to review.

Half of the file generated are regenerated binary

@subham8907

Copy link
Copy Markdown
Contributor Author

Sorry, huge PR with AI generated content will not be merged. It's too much to review.

Half of the file generated are regenerated binary

Atleast check the pr which file change

@subham8907

Copy link
Copy Markdown
Contributor Author

Sorry, huge PR with AI generated content will not be merged. It's too much to review.

Half of the file generated are regenerated binary

I mean good for you half of thing are regenerated binary never review single line then accuse other why use ai brother you use ai yourself stop moral policing about ai uses btw most of time i donot use ai anyway even if I do it doesnot matter it works

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.

2 participants