Skip to content

Fix Rust initialize JNI return type#167

Merged
ErikBjare merged 1 commit into
ActivityWatch:masterfrom
cosine0:fix-rust-interface-initialize-return-type
Jul 1, 2026
Merged

Fix Rust initialize JNI return type#167
ErikBjare merged 1 commit into
ActivityWatch:masterfrom
cosine0:fix-rust-interface-initialize-return-type

Conversation

@cosine0

@cosine0 cosine0 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Fixes a JNI return type mismatch for initialize. The native initialize method does not return a value, so the Kotlin external declaration should use Unit instead of String.

Verification:

  • Reproduced before this fix on the Pixel 9 emulator, Android 16 / x86_64: launching the pre-fix debug APK crashes immediately after aw-server-rust: Initializing aw-server-rust... with Fatal signal 11 (SIGSEGV). The native backtrace includes art::CheckReferenceResult, art::GenericJniMethodEnd, and net.activitywatch.android.RustInterface.<init>.
  • Verified the fixed debug APK on the same emulator: the app launches, aw-server-rust starts at 127.0.0.1:5600, and no AndroidRuntime, libc, or DEBUG fatal crash logs are emitted during startup.
  • ./gradlew.bat :mobile:testDebugUnitTest passed with Temurin 17.

Related issue:

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown

Greptile Summary

Fixes a JNI signature mismatch where the Kotlin external declaration for initialize() incorrectly declared a String return type while the Rust native implementation returns void. The call site in the init block already discarded the return value, so no callers need updating.

  • Removes : String from private external fun initialize() to match the actual Rust JNI signature, preventing a JNI type mismatch that would cause a runtime crash when the method is called.

Confidence Score: 5/5

Safe to merge — this is a single-line correction that aligns the Kotlin external declaration with the Rust native implementation's actual void return.

The change removes an incorrect : String return type from initialize(). The call site already discarded the return value, and the Rust native implementation returns void, so this fix is both necessary and complete. No other code paths are affected.

No files require special attention.

Important Files Changed

Filename Overview
mobile/src/main/java/net/activitywatch/android/RustInterface.kt Corrects the JNI external declaration for initialize() from String return type to Unit/void; call site already discards the return value, so no other code needs updating.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant K as RustInterface (Kotlin)
    participant J as JNI Bridge
    participant R as aw_server (Rust)

    K->>J: initialize() [Unit]
    J->>R: "Java_..._initialize(JNIEnv*, jobject)"
    R-->>J: void
    J-->>K: (no return value)
    K->>J: setDataDir(path: String)
    J->>R: "Java_..._setDataDir(JNIEnv*, jobject, jstring)"
    R-->>J: void
    J-->>K: (no return value)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant K as RustInterface (Kotlin)
    participant J as JNI Bridge
    participant R as aw_server (Rust)

    K->>J: initialize() [Unit]
    J->>R: "Java_..._initialize(JNIEnv*, jobject)"
    R-->>J: void
    J-->>K: (no return value)
    K->>J: setDataDir(path: String)
    J->>R: "Java_..._setDataDir(JNIEnv*, jobject, jstring)"
    R-->>J: void
    J-->>K: (no return value)
Loading

Reviews (1): Last reviewed commit: "Fix Rust initialize JNI return type" | Re-trigger Greptile

@ErikBjare
ErikBjare merged commit edca195 into ActivityWatch:master Jul 1, 2026
8 checks passed
@cosine0
cosine0 deleted the fix-rust-interface-initialize-return-type branch July 1, 2026 13: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.

2 participants