Android: crash on first sys_special("android_internal_storage_path") — getFilesDir requested with wrong JNI signature
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
Research direction
Read src/std/sys_android.c and inspect hl_sys_android_get_internal_storage_path() alongside the JNI helper it calls. The issue identifies the incorrect signature and the expected getFilesDir() result; update the call and check the Android build or run the reproduction to confirm it returns the internal files path without a JNI crash.
Written by the indexing model from the issue text.
Description
Describe the bug
On Android (HL/C build, SDL backend), the first call to sys_special("android_internal_storage_path") crashes the app with a JNI error, and the process is killed:
JNI DETECTED ERROR IN APPLICATION: JNI CallObjectMethod called with pending exception java.lang.NoSuchMethodError: no non-static method "Lcom/org1/app1/MainActivity;.getFilesDir(Ljava/lang/String;)Ljava/io/File;"
at int org.libsdl.app.SDLActivity.nativeRunMain(java.lang.String, java.lang.String, java.lang.Object) (SDLActivity.java:-2)
at void org.libsdl.app.SDLActivity.main() (SDLActivity.java:260)
at void org.libsdl.app.SDLMain.run() (SDLMain.java:2174)
at void java.lang.Thread.run() (Thread.java:1572)
in call to CallObjectMethod
from int org.libsdl.app.SDLActivity.nativeRunMain(java.lang.String, java.lang.String, java.lang.Object)
Root cause
src/std/sys_android.c, hl_sys_android_get_internal_storage_path():
hl_android_internal_files_path = hl_sys_android_get_absolute_path_from("getFilesDir", "(Ljava/lang/String;)Ljava/io/File;");
android.content.Context.getFilesDir() takes no arguments — its JNI signature is ()Ljava/io/File;. The (Ljava/lang/String;)Ljava/io/File; signature belongs to getExternalFilesDir(String type) (used a few lines above) and looks copy-pasted from there.
GetMethodID throws NoSuchMethodError; the exception is not checked, and the following CallObjectMethod with a pending exception aborts the process.
Present in release tag 1.16 and still in master @ 3d953ea (2026-11-10).
To reproduce
- Build any HL/C app for Android following the wiki (hashlink + SDL,
System.loadLibraryentry point). - From Haxe, request the internal storage path:
@:hlNative("std", "sys_special")
private static function sysSpecialNative(key:hl.Bytes):hl.Bytes {
return null;
}
var pathBytes = sysSpecialNative(@:privateAccess "android_internal_storage_path".bytes.utf16ToUtf8(0, null));
- Launch on a device (tested on Android 17, arm64-v8a).
Expected: returns /data/user/0/<package>/files.
Actual: immediate crash.
Suggested fix
- hl_android_internal_files_path = hl_sys_android_get_absolute_path_from("getFilesDir", "(Ljava/lang/String;)Ljava/io/File;");
+ hl_android_internal_files_path = hl_sys_android_get_absolute_path_from("getFilesDir", "()Ljava/io/File;");
(The NULL argument passed to CallObjectMethod inside the helper then becomes an ignored extra vararg per the JNI spec; it can be cleaned up as well.)
Workaround (for anyone hitting this now)
Add an overload to the activity / context-provider class that HL_ANDROID_ACTIVITY points to:
public java.io.File getFilesDir(String type) {
return getFilesDir();
}
hashlink then finds the (bogus) method signature it asks for, and everything works — this is how our game currently runs on devices.
Environment
- hashlink 1.16 (release tag) and master @
3d953ea - HL/C build (hlc), SDL3 backend (
libSDL3.soloaded separately fromSystem.loadLibrary, per the Android wiki) - Android 17 device, arm64-v8a, NDK 29
- Haxe 4.3.x, hlsdl 1.16.0
- Dominant language
- C
- Stars
- 911
- Forks
- 207
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 13
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from HaxeFoundation/hashlink
-
sys_full_path on Windows copies only half of each path part's case on diskPossibly taken @dimensionscape claimed this 1 day ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
HaxeFoundation/hashlink#1026 ·
Maintainers usually reply within 1 day
-
[Bug]hl_get_ustring() dereferences a NULL code->ustrings when the string table is empty (CWE-476)Possibly taken @1820893135-pixel claimed this 29 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
HaxeFoundation/hashlink#997 · 3 comments ·
Maintainers usually reply within 1 day
-
[Bug]hl_code_read(): unvalidated negative string-table size corrupts the bump allocator, leading to an out-of-bounds memset in hl_zalloc() (CWE-787 / CWE-190)Possibly taken @1820893135-pixel claimed this 29 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
HaxeFoundation/hashlink#996 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 64/100
HaxeFoundation/hashlink#397 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
HaxeFoundation/hashlink#1025 · 1 comment ·
Maintainers usually reply within 1 day
All issues in HaxeFoundation/hashlink
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
SanderMertens/flecs#2446 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kornelski/rust-lcms2#27 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
zmkfirmware/zmk#3571 ·
Maintainers usually reply within 10 days
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Stream parser writes past `esc_buff` after an invalid escapePossibly taken @benmandrew claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100