diff --git a/cargo-apk/CHANGELOG.md b/cargo-apk/CHANGELOG.md index 221f851e..4b0c7f4f 100644 --- a/cargo-apk/CHANGELOG.md +++ b/cargo-apk/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +- **Breaking**: Default `target_sdk_version` to `29` or lower for more consistent + interaction with Android backwards compatibility and tighter rules: + https://developer.android.com/distribute/best-practices/develop/target-sdk + # 0.8.2 (2021-11-22) - Fixed the library name in case of multiple build artifacts in the Android manifest. diff --git a/cargo-apk/README.md b/cargo-apk/README.md index 0408eb0f..90116a39 100644 --- a/cargo-apk/README.md +++ b/cargo-apk/README.md @@ -49,7 +49,7 @@ runtime_libs = "path/to/libs_folder" # See https://developer.android.com/guide/topics/manifest/uses-sdk-element # -# Defaults to a `min_sdk_version` of 23 and `target_sdk_version` is based on the ndk's default platform. +# Defaults to a `min_sdk_version` of 23 and `target_sdk_version` of 29 (or lower if the detected NDK doesn't support this). [package.metadata.android.sdk] min_sdk_version = 16 target_sdk_version = 29 diff --git a/cargo-apk/src/apk.rs b/cargo-apk/src/apk.rs index 87af153b..092f9239 100644 --- a/cargo-apk/src/apk.rs +++ b/cargo-apk/src/apk.rs @@ -59,13 +59,13 @@ impl<'a> ApkBuilder<'a> { .android_manifest .sdk .target_sdk_version - .get_or_insert(ndk.default_platform()); + .get_or_insert_with(|| ndk.default_target_platform()); manifest .android_manifest .application .debuggable - .get_or_insert(*cmd.profile() == Profile::Dev); + .get_or_insert_with(|| *cmd.profile() == Profile::Dev); Ok(Self { cmd, @@ -238,7 +238,7 @@ impl<'a> ApkBuilder<'a> { .android_manifest .sdk .target_sdk_version - .unwrap_or_else(|| ndk.default_platform()); + .unwrap_or_else(|| ndk.default_target_platform()); for target in &self.build_targets { let mut cargo = cargo_ndk(&ndk, *target, target_sdk_version)?; cargo.args(self.cmd.args()); diff --git a/ndk-build/CHANGELOG.md b/ndk-build/CHANGELOG.md index ed4b1e29..ea1754a8 100644 --- a/ndk-build/CHANGELOG.md +++ b/ndk-build/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +- **Breaking**: Default `target_sdk_version` to `29` or lower for more consistent + interaction with Android backwards compatibility and tighter rules: + https://developer.android.com/distribute/best-practices/develop/target-sdk + # 0.4.3 (2021-11-22) - Provide NDK `build_tag` version from `source.properties` in the NDK root. diff --git a/ndk-build/src/apk.rs b/ndk-build/src/apk.rs index 43548d0d..b6e6b165 100644 --- a/ndk-build/src/apk.rs +++ b/ndk-build/src/apk.rs @@ -40,7 +40,7 @@ impl ApkConfig { .manifest .sdk .target_sdk_version - .unwrap_or_else(|| self.ndk.default_platform()); + .unwrap_or_else(|| self.ndk.default_target_platform()); let mut aapt = self.build_tool(bin!("aapt"))?; aapt.arg("package") .arg("-f") diff --git a/ndk-build/src/ndk.rs b/ndk-build/src/ndk.rs index a53c40e8..1e1ee115 100644 --- a/ndk-build/src/ndk.rs +++ b/ndk-build/src/ndk.rs @@ -159,10 +159,18 @@ impl Ndk { Ok(Command::new(dunce::canonicalize(path)?)) } - pub fn default_platform(&self) -> u32 { + pub fn highest_supported_platform(&self) -> u32 { self.platforms().iter().max().cloned().unwrap() } + /// Returns platform `29` as currently [required by Google Play], or lower + /// when the detected SDK does not support it yet. + /// + /// [required by Google Play]: https://developer.android.com/distribute/best-practices/develop/target-sdk + pub fn default_target_platform(&self) -> u32 { + self.highest_supported_platform().min(29) + } + pub fn platform_dir(&self, platform: u32) -> Result { let dir = self .sdk_path