bevyengine / bevyengine/bevy

Persistent settings (SettingsPlugin, SettingsGroup, ...) does not work on Android

Open
#25,606 4 comments 1 reaction 0 assignees View on GitHub
A-Settings C-Bug D-Modest O-Android S-Needs-Design X-Uncontroversial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version and features

- Bevy 0.19.1

## What I did

I used bevy persistent settings, in a very similar way to the `app/settings.rs` example, it works on Linux, but not on Android.

## Additional information

I worked around the issue by modifying `bevy_platform/src/dirs/mod.rs` to become
```rust
//! APIs that return the location of standard user directories.

// Modeled after https://github.com/dirs-dev/dirs-sys-rs/

#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
use std::path::PathBuf;

#[cfg(target_os = "windows")]
mod windows;
#[cfg(target_os = "windows")]
pub use windows::preferences_dir;

#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
pub use macos::preferences_dir;

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use linux::preferences_dir;

#[cfg(target_os = "android")]
pub fn preferences_dir() -> Option {
Some(PathBuf::from("/data/data"))
}

/// Returns the path to the directory used for application settings. This version
/// always returns `None`.
#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "android"
)))]
pub fn preferences_dir() -> Option {
None
}
```
The important added part being
```rust
#[cfg(target_os = "android")]
pub fn preferences_dir() -> Option {
Some(PathBuf::from("/data/data"))
}
```
I have almost no Android experience and I am not 100% sure this is the best way to do this on Android but "it worked for me". I will make a PR as soon as possible. Like kfc35 suggested on Discord: I will put the android specifics in a separate file (even if almost empty like it is for macos) and not in the `mod.rs`

Contributor guide

Open the contributing guide

Research direction

Start with bevy_platform/src/dirs/mod.rs and the app/settings.rs example, then review how platform-specific directory implementations are organized, including the separate macOS file. Add Android-specific handling without hard-coding an unsuitable path, and verify that persistent settings work in the Android version of the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.