Skip to content

Commit d2b8af6

Browse files
committed
Replace unmaintained android-properties crate with ndk API
I was surprised to find [the `android-properties` crate] with almost 8 *million* downloads; this crate hasn't been updated for almost 5 years and the repository is a public archive. Turns out the only published user of this crate is `android-activity`, so all those downloads are pulled in from folks using this crate (mainly through `winit`) to build Android apps. Instead of using an unmaintained, archived crate, use the properties wrapper and typed API-level wrappers provided in in an upcoming `ndk` crate release instead: - rust-mobile/ndk#495 - rust-mobile/ndk#479 [the `android-properties` crate]: https://crates.io/crates/android-properties
1 parent 1652ebb commit d2b8af6

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ resolver = "2"
33
members = ["android-activity"]
44

55
exclude = ["examples"]
6+
7+
[patch.crates-io]
8+
# https://github.com/rust-mobile/ndk/pull/495
9+
ndk = { git = "https://github.com/rust-mobile/ndk", rev = "9c63222" }

android-activity/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ jni = "0.21"
4242
ndk-sys = "0.6.0"
4343
ndk = { version = "0.9.0", default-features = false }
4444
ndk-context = "0.1.1"
45-
android-properties = "0.2"
4645
num_enum = "0.7"
4746
bitflags = "2.0"
4847
libc = "0.2.139"

android-activity/src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -855,15 +855,14 @@ impl AndroidApp {
855855

856856
/// The user-visible SDK version of the framework
857857
///
858-
/// Also referred to as [`Build.VERSION_CODES`](https://developer.android.com/reference/android/os/Build.VERSION_CODES)
858+
/// The same value as [`Build.VERSION.SDK_INT`], containing a value from [`Build.VERSION_CODES`].
859+
///
860+
/// [`Build.VERSION.SDK_INT`]: https://developer.android.com/reference/android/os/Build.VERSION#SDK_INT
861+
/// [`Build.VERSION_CODES`]: https://developer.android.com/reference/android/os/Build.VERSION_CODES
859862
pub fn sdk_version() -> i32 {
860-
let mut prop = android_properties::getprop("ro.build.version.sdk");
861-
if let Some(val) = prop.value() {
862-
val.parse::<i32>()
863-
.expect("Failed to parse ro.build.version.sdk property")
864-
} else {
865-
panic!("Couldn't read ro.build.version.sdk system property");
866-
}
863+
// TODO: Replace with ndk::api_level::device_api_level() from https://github.com/rust-mobile/ndk/pull/479?
864+
ndk::system_properties::get::<i32>(c"ro.build.version.sdk")
865+
.expect("Failed to get or parse `ro.build.version.sdk` property")
867866
}
868867

869868
/// Path to this application's internal data directory

0 commit comments

Comments
 (0)