pub const ANDROID_NDK_VERSION: &str = "29.0.14206865";
#[must_use]
pub fn parse_android_ndk_version_from_runtime_build_gradle(contents: &str) -> Option<String> {
contents.lines().find_map(|line| {
let line = line.split("//").next()?.trim();
let remainder = line.strip_prefix("ndkVersion")?;
let (_, value) = remainder.split_once('=')?;
let version = value.trim().trim_matches('"');
if version.is_empty() {
None
} else {
Some(version.to_string())
}
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_android_ndk_version_from_runtime_build_gradle_extracts_declared_version() {
let contents = r#"
android {
compileSdk = 37
ndkVersion = "29.0.14206865"
}
"#;
assert_eq!(
parse_android_ndk_version_from_runtime_build_gradle(contents),
Some("29.0.14206865".to_string())
);
}
#[test]
#[ignore = "fetches the pinned water-rs/android-backend revision over the network"]
fn embedded_ndk_version_matches_the_pinned_android_backend() {
let (framework, revision) = crate::pinned_framework::source();
let (backend_commit, backend) =
crate::pinned_framework::android_backend(&framework, &revision);
let contents = String::from_utf8(crate::pinned_framework::fetch(
&crate::pinned_framework::raw_url(
&backend,
&backend_commit,
"runtime/build.gradle.kts",
),
))
.expect("runtime build.gradle.kts is UTF-8");
assert_eq!(
parse_android_ndk_version_from_runtime_build_gradle(&contents).as_deref(),
Some(ANDROID_NDK_VERSION),
"ANDROID_NDK_VERSION drifted from the pinned android-backend's \
runtime `ndkVersion` ({backend}@{backend_commit})"
);
}
}