Android: crash on first sys_special("android_internal_storage_path") — getFilesDir requested with wrong JNI signature

Open Beginner friendly
#1,016 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, c
Domain
mobile

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

  1. Build any HL/C app for Android following the wiki (hashlink + SDL, System.loadLibrary entry point).
  2. 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));
  1. 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.so loaded separately from System.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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HaxeFoundation/hashlink

All issues in HaxeFoundation/hashlink

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.