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

Make android-activity dependency optional #2834

Closed
wants to merge 3 commits into from

Conversation

ardocrat
Copy link

This allows Android-targeting builds to use not only native-activity, but game-activity and avoids using a specific version of android-activity because Egui doesn't directly use the android-activity API.

@ardocrat ardocrat changed the title Make android-activity dependency a feature Make android-activity dependency optional Mar 23, 2023
@podusowski
Copy link

How do you select which type of the activity you app uses after this merge? By explicitly adding android-activity to your app?

@ardocrat
Copy link
Author

How do you select which type of the activity you app uses after this merge? By explicitly adding android-activity to your app?

I simply use android-activity = { version = "0.4", features = ["game-activity"] } at my dependencies.

@rib
Copy link
Contributor

rib commented Mar 23, 2023

Applications that are based on Winit should use the android-native-activity and android-game-activity features from Winit.

These features will result in Winit adding the required dependency on android-activity and it will also mean that egui or your application crate doesn't need to specify any version for depending on android-activity. (Potentially leading to a conflict in the future if Winit bumps the version of android-activity that it uses)

I think egui-winit should probably do the same as Winit here and provide android-native-activity and android-game-activity features that just map to the Winit features.

This way egui-winit never directly depends on android-activity unless it needs to directly use the android-activity API in the future.

CI can then hopefully just pick one of these features to use.

@emilk
Copy link
Owner

emilk commented Mar 29, 2023

cargo check --features wgpu --target aarch64-linux-android fails

rib added a commit to rib/egui that referenced this pull request Mar 29, 2023
Instead of depending on android-activity directly, this exposes the
android-native-activity and android-game-activity features from Winit.

This ensures that applications can choose what android-backend they use
while also relying on Winit to decide what version of android-activity to
use - without increasing the risk of a version conflict by having a direct
dependency.

_(NB: Egui doesn't currently use the android-activity API itself)_

Since android-activity provides the `android_main()` entry point for
Android applications it's not possible to link in multiple version of
the android-activity crate and so it's particularly important to
avoid unnecessary direct dependencies that could cause a version
conflict in the future.

To help avoid the need for applications to directly depend on
android-activity the Winit crate re-exports the android-activity API
and exposes features to configure the backend so that application crates
can instead rely on Winit to pull in a compatible version of
android-activity. (This way version bumps for android-activity only
need to be synchronized with the Winit crate).

CI now enables the `android-native-activity` feature for testing.

Fixes: emilk#2829
Fixes: emilk#2720
Closes: emilk#2834
rib added a commit to rib/egui that referenced this pull request Apr 1, 2023
Instead of depending on android-activity directly, this exposes the
android-native-activity and android-game-activity features from Winit.

This ensures that applications can choose what android-backend they use
while also relying on Winit to decide what version of android-activity to
use - without increasing the risk of a version conflict by having a direct
dependency.

_(NB: Egui doesn't currently use the android-activity API itself)_

Since android-activity provides the `android_main()` entry point for
Android applications it's not possible to link in multiple version of
the android-activity crate and so it's particularly important to
avoid unnecessary direct dependencies that could cause a version
conflict in the future.

To help avoid the need for applications to directly depend on
android-activity the Winit crate re-exports the android-activity API
and exposes features to configure the backend so that application crates
can instead rely on Winit to pull in a compatible version of
android-activity. (This way version bumps for android-activity only
need to be synchronized with the Winit crate).

CI now enables the `android-native-activity` feature for testing.

Fixes: emilk#2829
Fixes: emilk#2720
Closes: emilk#2834
@rib
Copy link
Contributor

rib commented Apr 1, 2023

I've opened up an alternative PR #2863 to hopefully address this issue by exposing features for the different backends (even though that may seem awkward; please see the PR for an explanation of why I think that's the appropriate solution here)

How do you select which type of the activity you app uses after this merge? By explicitly adding android-activity to your app?

I simply use android-activity = { version = "0.4", features = ["game-activity"] } at my dependencies.

If possible, I would generally recommend aiming to avoid adding a direct dependency on android-activity to your app if you don't make any significant use of the android-activity API.

Instead try to use the API re-exported from winit, e.g. like:

#[cfg(target_os = "android")]
use winit::platform::android::activity::AndroidApp;

By minimizing the number of crates that explicitly depend on the android-activity crate then it should be less painful to manage semver bumps for the android-activity crate if needed in the future (in situations where you're relying on some middleware crate like Winit to generally deal with the android-activity API).

The problem with adding a direct dependency is that Winit is much more likely to be opinionated about what version of android-activity it depends on and due to the runtime nature of the android-activity crate you will end up with a link-time build failure in the future if your app crate depends on a version that's not semver compatible with the version that Winit depends on.

@ardocrat
Copy link
Author

ardocrat commented Apr 10, 2023

Better fix: #2863

@ardocrat ardocrat closed this Apr 10, 2023
emilk pushed a commit that referenced this pull request Apr 18, 2023
Instead of depending on android-activity directly, this exposes the
android-native-activity and android-game-activity features from Winit.

This ensures that applications can choose what android-backend they use
while also relying on Winit to decide what version of android-activity to
use - without increasing the risk of a version conflict by having a direct
dependency.

_(NB: Egui doesn't currently use the android-activity API itself)_

Since android-activity provides the `android_main()` entry point for
Android applications it's not possible to link in multiple version of
the android-activity crate and so it's particularly important to
avoid unnecessary direct dependencies that could cause a version
conflict in the future.

To help avoid the need for applications to directly depend on
android-activity the Winit crate re-exports the android-activity API
and exposes features to configure the backend so that application crates
can instead rely on Winit to pull in a compatible version of
android-activity. (This way version bumps for android-activity only
need to be synchronized with the Winit crate).

CI now enables the `android-native-activity` feature for testing.

Fixes: #2829
Fixes: #2720
Closes: #2834
TicClick pushed a commit to TicClick/egui that referenced this pull request Apr 18, 2023
Instead of depending on android-activity directly, this exposes the
android-native-activity and android-game-activity features from Winit.

This ensures that applications can choose what android-backend they use
while also relying on Winit to decide what version of android-activity to
use - without increasing the risk of a version conflict by having a direct
dependency.

_(NB: Egui doesn't currently use the android-activity API itself)_

Since android-activity provides the `android_main()` entry point for
Android applications it's not possible to link in multiple version of
the android-activity crate and so it's particularly important to
avoid unnecessary direct dependencies that could cause a version
conflict in the future.

To help avoid the need for applications to directly depend on
android-activity the Winit crate re-exports the android-activity API
and exposes features to configure the backend so that application crates
can instead rely on Winit to pull in a compatible version of
android-activity. (This way version bumps for android-activity only
need to be synchronized with the Winit crate).

CI now enables the `android-native-activity` feature for testing.

Fixes: emilk#2829
Fixes: emilk#2720
Closes: emilk#2834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants