Skip to content

ant-ffi: Client constructors should accept an explicit data_dir (Android needs it) #165

Description

@Nic-dorman

Problem

ant-core::config::home_dir() reads $HOME (or $USERPROFILE) unconditionally and returns Error::HomeDirNotFound if neither is set. This trips every ant-ffi Client constructor on Android, because Android app processes don't inherit a HOME env var by default — Zygote/ART set up the process environment minimally.

Concrete repro: in the AntAndroidDemo (PR adds it to ant-android/Examples/) or in the SmokeTest in AntAndroidSmoke, calling any Client.connectXxx() from a freshly launched Android app fails immediately with:

uniffi.ant_ffi.InternalException: called `Result::unwrap()` on an `Err` value: HomeDirNotFound

Current workaround

Plant HOME via libc setenv before the first FFI call (we use JNA in the demo/smoke):

internal interface LibC : Library {
    fun setenv(name: String, value: String, overwrite: Int): Int
    companion object { val INSTANCE: LibC = Native.load("c", LibC::class.java) }
}
// Once at app startup:
LibC.INSTANCE.setenv("HOME", context.filesDir.absolutePath, 1)

This works but it's ugly, racy across multi-process apps, and obscures the real intent (the app is choosing where the SDK should put its data).

Proposed fix

Add an explicit data_dir: String (or Option<String>) parameter to the FFI constructors:

  • Client.connect_local(data_dir: Option<String>)
  • Client.connect(peers, data_dir: Option<String>)
  • Client.connect_with_wallet(..., data_dir: Option<String>)
  • Client.connect_from_devnet_manifest(path, data_dir: Option<String>)

When None, fall back to the current ant_core::config::data_dir() behaviour (so existing macOS/iOS/Linux callers don't have to change anything).

On Android, consumers pass Context.filesDir.absolutePath. On iOS, the app's sandbox documents/library dir. On macOS/Linux, can stay None.

Related

Surfaced during the runtime smoke for ant-android v0.0.1 — see PR #156. The libc shim is committed in AntAndroidDemo and the smoke test until this lands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions