[stable] Fix flutter run failing when the launcher activity is an <activity-alias> (cherry-pick of #187251) - #192726
Conversation
…r#187251) Fixes `flutter run` failing with "package identifier or launch activity not found" when the MAIN/LAUNCHER intent-filter is declared on an <activity-alias> rather than directly on an <activity>. Fixes: flutter#38965 (cherry picked from commit 05f1a0b)
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates AndroidApk.fromAndroidProject to support parsing activity-alias elements alongside activity elements in the Android manifest when identifying the launch activity, and adds corresponding unit tests. Feedback suggests simplifying the loop control logic by checking if launchActivity is non-null instead of introducing a new foundLauncher boolean variable.
Cherry-pick of #187251 (commit
05f1a0bdd2b522b3b63442723a06577557e7361f) ontoflutter-3.47-candidate.0, requested for the next stable hotfix.Fixes #38965.
Issue
flutter runandflutter installabort on Android with:whenever the
MAIN/LAUNCHERintent-filter is declared on an<activity-alias>instead of directly on an<activity>. The manifest is not actually in error — the same project installs and launches correctly via./gradlew installDebug. The tool's launch-activity detection only walked<activity>elements, so it found no launcher and reported a misleading manifest failure.Impacted Users
Android developers whose
AndroidManifest.xmluses<activity-alias>as the MAIN/LAUNCHER entry point — a documented Android pattern used to swap launcher icons and labels, to keep a stable launcher component name across activity refactors, and in white-label / flavored builds.Impact Description
Development on Android is blocked for these projects:
flutter runandflutter installcannot start the app, and the error text points at the manifest as though it were malformed, which sends developers looking for a non-existent manifest bug. Artifacts built by Gradle are unaffected — the failure is in the tool's launch path, not in the built app.Workaround
Partially. The MAIN/LAUNCHER intent-filter can be moved off the alias and onto the target
<activity>, but that changes the launcher component name Android exposes, so it is not viable for apps that depend on a stable alias name (for example to preserve homescreen shortcuts), and it has to be reverted before shipping.Risk
Low. The change is confined to
flutter_toolsmanifest parsing:<activity-alias>elements are appended after<activity>elements withfollowedBy, so plain<activity>matches keep priority and existing manifests resolve to exactly the same launch activity as before.android:nameno longer yields a malformedpackage/nulllaunch activity.No framework, engine, or build-output changes.
Test Coverage
Yes — +145 lines of unit tests in
packages/flutter_tools/test/general.shard/application_package_test.dart:AndroidApk.fromAndroidProjectresolves an<activity-alias>launcher fromAndroidManifest.xml.ApkManifestData.parseFromXmlDumpresolves anactivity-aliaslauncher from anaaptdump.android:namereturnsnullrather than a malformed component.Existing launcher-detection tests are unchanged.
Validation Steps
flutter create activity_alias && cd activity_aliasandroid/app/src/main/AndroidManifest.xml, remove the<intent-filter>from.MainActivityand add:flutter runon a connected Android device or emulator.package identifier or launch activity not found.<package>/.LauncherAlias.<activity>-only manifest andflutter runagain — still launches.MainActivity.Cherry-pick notes
application_package.dartapplied cleanly.application_package_test.dartrequired a three-way merge against unrelated formatting churn on the candidate branch; it resolved without conflicts and the resulting diff is identical in size to the original PR (+13/−3 and +145/−0).I do not have triage permission on this repository, so I could not apply the
cp: reviewlabel — could a triager please add it?cc @mboetger (author of the original PR).
🤖 Generated with Claude Code