Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo-apk: Export native activity by default on Android S and up #242

Merged
merged 2 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cargo-apk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://developer.android.com/distribute/best-practices/develop/target-sdk
- Allow manifest `package` property to be provided in `Cargo.toml`. ([#236](https://github.com/rust-windowing/android-ndk-rs/pull/236))
- Add `MAIN` intent filter in `from_subcommand` instead of relying on a custom serialization function in `ndk-build`. ([#241](https://github.com/rust-windowing/android-ndk-rs/pull/241))
- Export the sole `NativeActivity` (through `android:exported="true"`) to allow it to be started by default if targeting Android S or higher. ([#242](https://github.com/rust-windowing/android-ndk-rs/pull/242))

# 0.8.2 (2021-11-22)

Expand Down
5 changes: 5 additions & 0 deletions cargo-apk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ launch_mode = "singleTop"
# Defaults to "unspecified".
orientation = "landscape"

# See https://developer.android.com/guide/topics/manifest/activity-element#exported
#
# Unset by default, or "true" when targeting Android >= 31 (S and up).
exported = "true"

# See https://developer.android.com/guide/topics/manifest/meta-data-element
#
# Note: there can be several .meta_data entries.
Expand Down
9 changes: 8 additions & 1 deletion cargo-apk/src/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<'a> ApkBuilder<'a> {
panic!("version_code should not be set in TOML");
}

manifest
let target_sdk_version = *manifest
.android_manifest
.sdk
.target_sdk_version
Expand All @@ -80,6 +80,13 @@ impl<'a> ApkBuilder<'a> {
});
}

// Export the sole Rust activity on Android S and up, if the user didn't explicitly do so.
// Without this, apps won't start on S+.
// https://developer.android.com/about/versions/12/behavior-changes-12#exported
if target_sdk_version >= 31 {
activity.exported.get_or_insert(true);
}
MarijnS95 marked this conversation as resolved.
Show resolved Hide resolved

Ok(Self {
cmd,
ndk,
Expand Down
1 change: 1 addition & 0 deletions ndk-build/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
https://developer.android.com/distribute/best-practices/develop/target-sdk
- Remove default insertion of `MAIN` intent filter through a custom serialization function, this is better filled in by
the default setup in `cargo-apk`. ([#241](https://github.com/rust-windowing/android-ndk-rs/pull/241))
- Add `android:exported` attribute to the manifest's `Activity` element. ([#242](https://github.com/rust-windowing/android-ndk-rs/pull/242))

# 0.4.3 (2021-11-22)

Expand Down
3 changes: 3 additions & 0 deletions ndk-build/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ pub struct Activity {
pub name: String,
#[serde(rename(serialize = "android:screenOrientation"))]
pub orientation: Option<String>,
#[serde(rename(serialize = "android:exported"))]
pub exported: Option<bool>,

#[serde(rename(serialize = "meta-data"))]
#[serde(default)]
Expand All @@ -111,6 +113,7 @@ impl Default for Activity {
launch_mode: None,
name: default_activity_name(),
orientation: None,
exported: None,
meta_data: Default::default(),
intent_filters: Default::default(),
}
Expand Down