fix(android): jstring_to_string function to properly convert Java strings #547
+2 −2
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Problem
Android app crashes on startup with SIGABRT and
NulErrorin SQLite path creation. The Rust native code receives empty strings from Java/Kotlin via JNI.Root Cause
The
jstring_to_stringfunction insrc/android/mod.rsincorrectly converted JNI strings usingCStr::from_ptron 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_stringhelper function to use the properJNIEnv::get_stringAPI which correctly handles the conversion from Java strings to Rust strings.Changes Made
jstring_to_stringfunction insrc/android/mod.rsCStr::from_ptrapproachenv.get_string(string).expect("...").into()for proper conversionTesting
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_stringinmod.rsfor correct Java to Rust string conversion, resolving app crash issue.jstring_to_stringinmod.rsto useJNIEnv::get_stringinstead ofCStr::from_ptrfor correct Java to Rust string conversion.This description was created by
for 0cff97d. You can customize this summary. It will automatically update as commits are pushed.