Skip to content

Conversation

@kenoma-hld
Copy link

@kenoma-hld kenoma-hld commented Dec 11, 2025

Problem

Android app crashes on startup with SIGABRT and NulError in SQLite path creation. The Rust native code receives empty strings from Java/Kotlin via JNI.

Root Cause

The jstring_to_string function in src/android/mod.rs incorrectly converted JNI strings using CStr::from_ptr on raw pointers. This approach doesn't work with JNI's internal string representation, resulting in empty strings being passed to subsequent functions.

Solution

Fixed the jstring_to_string helper function to use the proper JNIEnv::get_string API which correctly handles the conversion from Java strings to Rust strings.

Changes Made

  • Fixed: jstring_to_string function in src/android/mod.rs
    • Changed from incorrect CStr::from_ptr approach
    • Now uses env.get_string(string).expect("...").into() for proper conversion

Testing

  • Verified with aw-android companion app
  • App no longer crashes on startup
  • Datastore correctly initializes at the specified path
  • All JNI string conversions now work correctly

Impact

This minimal fix resolves the crash while maintaining full backward compatibility. No other changes to the codebase were required.

Related Issue

Fixes ActivityWatch/aw-android#110 - App crashes on launch on Android 13


Important

Fix jstring_to_string in mod.rs for correct Java to Rust string conversion, resolving app crash issue.

  • Bug Fix:
    • Fix jstring_to_string in mod.rs to use JNIEnv::get_string instead of CStr::from_ptr for correct Java to Rust string conversion.
  • Testing:
    • Verified with aw-android app; no startup crashes.
    • Datastore initializes correctly; all JNI string conversions work.
  • Impact:
    • Resolves crash issue, maintains backward compatibility.
  • Related Issue:

This description was created by Ellipsis for 0cff97d. You can customize this summary. It will automatically update as commits are pushed.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to 0cff97d in 34 seconds. Click for details.
  • Reviewed 15 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. aw-server/src/android/mod.rs:85
  • Draft comment:
    Good fix: using env.get_string(...).into() properly converts JString to a Rust String. This is more robust than manually using CStr::from_ptr.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_LcOEsuabgMunAklM

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@kenoma-hld kenoma-hld changed the title Fix Android JString conversion fix(android): jstring_to_string function to properly convert Java strings Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant