Skip to content

Conversation

@0xbrayo
Copy link
Member

@0xbrayo 0xbrayo commented Dec 22, 2025

Important

Adds Android support to aw-sync with JNI bindings and updates the build process for Android targets.

  • Android Support:
    • Adds aw-sync/src/android.rs for JNI bindings to support Android.
    • Implements functions: syncPullAll, syncPull, syncPush, syncBoth, and getSyncDir for Android.
  • Build Process:
    • Updates compile-android.sh to build aw-sync for Android without CLI features.
    • Modifies Cargo.toml to include jni dependency for Android and make CLI dependencies optional.
  • Code Structure:
    • Adds push_with_hostname() in sync_wrapper.rs and lib.rs for hostname-specific sync operations.
    • Updates dirs.rs and util.rs to conditionally compile Android-specific code.

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

Phase 1: Library Preparation
- Made CLI dependencies (clap, ctrlc) optional in Cargo.toml
- Added jni dependency for Android target
- Added android module to lib.rs with conditional compilation
- Created android.rs with JNI bindings for sync operations:
  * syncPullAll - pull from all hosts
  * syncPull - pull from specific host
  * syncPush - push local data
  * syncBoth - full bidirectional sync
  * getSyncDir - get current sync directory path
- Made main.rs conditional on 'cli' feature for Android compatibility

Phase 2: Android Build Integration
- Updated compile-android.sh to build aw-sync alongside aw-server
- aw-sync built with --no-default-features to exclude CLI dependencies
- Libraries generated for all Android architectures (arm64, x86_64, x86, arm)

JNI functions return JSON responses with success/error status.
All sync operations use the existing aw-sync Rust API.
Sync directory configurable via AW_SYNC_DIR environment variable.

Next: Android app integration (phases 4-5) in aw-android repo.
…i feature

The SyncMode enum now only derives ValueEnum when the cli feature is enabled.
This allows the library to compile without clap on Android.
- Remove unused imports (CString, CStr, get_server_port)
- Add explicit Result<String, String> type annotations for closures
- Fix hostname parameter to use reference (&hostname)
- Explicitly type error messages as &str for JSON serialization
- All compilation errors resolved
…ions for Android

- Made env parameter mutable in syncPull JNI function
- Made get_config_dir() conditional to not compile on Android
- Made get_server_config_path() conditional to not compile on Android
- These functions use appdirs which doesn't support Android
- Android uses environment variables (AW_SYNC_DIR) instead
- Made get_server_port function conditional to not compile on Android
- On Android, port is passed as parameter to JNI functions
- This avoids dependency on config file reading which is not available on Android
- Added crate-type = ["cdylib", "rlib"] to [lib] section
- cdylib is required to generate .so files for Android JNI
- rlib allows the library to be used by other Rust code
…ctory structure

- Updated JNI function signatures to accept hostname parameter
- Parse hostname from JString in syncPullAll, syncPush, syncBoth
- Set AW_HOSTNAME environment variable before sync operations
- This fixes sync directory structure to use actual device name instead of 'localhost'

Hostname is passed from Android Settings.Global.DEVICE_NAME or Build.MODEL
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.

Caution

Changes requested ❌

Reviewed everything up to 6d5086a in 2 minutes and 19 seconds. Click for details.
  • Reviewed 392 lines of code in 9 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 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-sync/Cargo.toml:27
  • Draft comment:
    Optional CLI dependencies are now gated under the 'cli' feature. Verify they are correctly included/excluded for Android builds.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. compile-android.sh:75
  • Draft comment:
    Appending to RUSTFLAGS using '+=' can be brittle. Consider quoting the output of the clang command to ensure proper handling across environments.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
3. compile-android.sh:100
  • Draft comment:
    Using '--no-default-features' for the aw-sync build excludes CLI dependencies intentionally. Confirm that this configuration doesn’t unintentionally remove functionality needed on Android.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None

Workflow ID: wflow_N6yvymWn6it8tVF3

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

@greptile-apps
Copy link

greptile-apps bot commented Dec 22, 2025

Greptile Summary

This PR adds Android support to aw-sync by creating a JNI interface that allows the Android app to call sync operations from native Rust code. The implementation cleanly separates CLI-specific dependencies (clap, ctrlc) from the library code using feature flags.

Key changes:

  • Added new android.rs module with JNI wrapper functions for sync operations (syncPull, syncPullAll, syncPush, syncBoth, getSyncDir)
  • Introduced cli feature flag (enabled by default) to make CLI dependencies optional
  • Added cdylib crate type for building shared library for Android
  • Refactored push() to extract push_with_hostname() that accepts explicit hostname parameter
  • Made Android-incompatible functions conditional with #[cfg(not(target_os = "android"))]
  • Updated build script to compile aw-sync for Android targets with --no-default-features

Minor issues:

  • AW_HOSTNAME environment variable is set but never read by any sync operations (unnecessary code)
  • Some error handling uses expect() which panics instead of gracefully returning errors

Confidence Score: 4/5

  • This PR is safe to merge with only minor style improvements needed
  • The implementation is solid with proper feature gating and conditional compilation. The refactoring to support explicit hostname passing is clean. Only minor issues found: unused environment variable setting and some non-critical error handling that could be improved. No logical errors or security issues detected.
  • Pay attention to aw-sync/src/android.rs for potential cleanup of unused environment variable setting

Important Files Changed

Filename Overview
aw-sync/src/android.rs New JNI interface for Android sync operations; unnecessary environment variable setting found
aw-sync/Cargo.toml Added feature flags and Android dependencies; clean separation of CLI vs library concerns
aw-sync/src/sync_wrapper.rs Refactored push to support explicit hostname parameter; clean implementation

Sequence Diagram

sequenceDiagram
    participant Android as Android App
    participant JNI as JNI Interface (android.rs)
    participant Client as AwClient
    participant Sync as Sync Operations
    participant FS as File System (Sync Dir)

    Note over Android,FS: Pull All Hosts Flow
    Android->>JNI: syncPullAll(port, hostname)
    JNI->>JNI: Convert JString to String
    JNI->>Client: get_client(port)
    Client-->>JNI: AwClient instance
    JNI->>Sync: pull_all(client)
    Sync->>FS: get_remotes()
    FS-->>Sync: List of host directories
    loop For each host
        Sync->>FS: Read host's .db files
        Sync->>Client: Import events from host
    end
    Sync-->>JNI: Success/Error
    JNI->>Android: JSON response

    Note over Android,FS: Push Flow
    Android->>JNI: syncPush(port, hostname)
    JNI->>JNI: Convert JString to String
    JNI->>Client: get_client(port)
    Client-->>JNI: AwClient instance
    JNI->>Sync: push_with_hostname(client, hostname)
    Sync->>FS: Create/update sync_dir/hostname/*
    Sync->>Client: Export local buckets
    Sync->>FS: Write events to .db files
    Sync-->>JNI: Success/Error
    JNI->>Android: JSON response

    Note over Android,FS: Full Sync Flow
    Android->>JNI: syncBoth(port, hostname)
    JNI->>Sync: pull_all(client)
    Sync-->>JNI: Pull complete
    JNI->>Sync: push_with_hostname(client, hostname)
    Sync-->>JNI: Push complete
    JNI->>Android: JSON response
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (3)

  1. aw-sync/src/android.rs, line 43 (link)

    style: Setting AW_HOSTNAME has no effect - no code reads this environment variable. The sync operations use the hostname parameter passed directly to functions, not from environment. Consider removing these set_var calls in syncPullAll, syncPush, and syncBoth.

  2. aw-sync/src/android.rs, line 12 (link)

    style: Panicking on string creation failure. Consider returning an error instead since JNI operations can fail.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  3. aw-sync/src/android.rs, line 59 (link)

    style: Unnecessary type annotation creates verbose code in multiple places.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

9 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.82%. Comparing base (656f3c9) to head (babea6c).
⚠️ Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
aw-sync/src/sync_wrapper.rs 0.00% 3 Missing ⚠️
aw-sync/src/main.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #548      +/-   ##
==========================================
- Coverage   70.81%   67.82%   -3.00%     
==========================================
  Files          51       54       +3     
  Lines        2916     3136     +220     
==========================================
+ Hits         2065     2127      +62     
- Misses        851     1009     +158     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@0xbrayo 0xbrayo force-pushed the aw-sync-android-support branch 2 times, most recently from c174a79 to 9567a1a Compare December 22, 2025 15:13
Copy link
Member

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

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

Great job on this, this is really going to make things next-level

@0xbrayo
Copy link
Member Author

0xbrayo commented Dec 22, 2025

Super excited for this feature 💯

@0xbrayo 0xbrayo force-pushed the aw-sync-android-support branch from 9567a1a to 9f42d3a Compare December 22, 2025 18:46
- Created push_with_hostname() function that accepts hostname parameter
- Updated JNI functions to use push_with_hostname() with passed hostname
- This ensures sync directory uses actual device name from Android
- Fixes issue where 'localhost' was used despite passing device name

The hostname is now passed directly from Android through JNI to the sync
functions, bypassing the client's hostname entirely.
@0xbrayo 0xbrayo force-pushed the aw-sync-android-support branch from 9f42d3a to 9c1bd01 Compare December 23, 2025 15:53
@0xbrayo
Copy link
Member Author

0xbrayo commented Dec 23, 2025

This is ready to merge :)

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