flutter / flutter/flutter

Add a way to supply Android manifest fragments from the Flutter SDK

Open
#152,991 2 comments 2 reactions 0 assignees View on GitHub
c: new feature c: proposal P2 platform-android team-android tool triaged-android
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Use case

Some features might require the addition of a section to the Android manifest file. This is the case for https://github.com/flutter/flutter/issues/139361.

The `flutter create` templates can be updated to add the required section to newly created projects, but this doesn't solve the problem for existing Flutter apps.

Potentially this could be handled by writing migrations to update the `AndroidManifest.xml` source files in the app's tree, but (a) migrations are always tricky; (b) if for some reason a developer wanted to opt out of a given change, that approach doesn't offer a great answer for them. So this issue proposes a different solution.

### Proposal

Add a way for the Flutter SDK to supply one more Android manifest source file for the Android build process to [merge together](https://developer.android.com/build/manage-manifests#merge-manifests) when it produces the manifest for the built app.

This is something Flutter plugins already routinely do. For Flutter itself, it'd probably involve adding an `AndroidManifest.xml` file somewhere in the framework tree under `packages/flutter_tools/`, like where the Gradle build scripts appear, and then having our Gradle build scripts include that file among the sources when building the app.

For any element we add that a developer wants to opt out of, they can always tell the Android build process to leave it out [by saying `tools:node="remove"`](https://developer.android.com/build/manage-manifests#node_markers) at a corresponding spot in their own `AndroidManifest.xml` source file.

Once we have that mechanism:
* We could use it for the `` element added in #137207. This would cause #139361 to start working for existing Flutter apps, fixing a platform-fidelity issue.
* We could use it for the INTERNET permission, which today is handled with the `flutter create` template: the template puts `` in the files `android/app/src/{debug,profile}/AndroidManifest.xml`. Using the new mechanism, those would become redundant and the template could be simplified by removing them — so in fact both those files can be completely deleted from the template.
* There may be other pieces of `AndroidManifest.xml` that would also be productive to move to this mechanism instead of the `flutter create` templates. In general, this should be used for details that are determined by Flutter and just need to be in the manifest for the Flutter tool and engine to fully do their jobs; the templates should be used where we're just filling in a starting point for the developer to adjust from there.

(Based on the discussion starting at https://github.com/flutter/flutter/issues/139361#issuecomment-1878206806 .)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.