-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Adds vmservices to retrieve android applink settings #125998
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -731,6 +731,85 @@ class FlutterPlugin implements Plugin<Project> { | |
| } | ||
| } | ||
|
|
||
| // Add a task that can be called on Flutter projects that prints application id of a build | ||
| // variant. | ||
| // | ||
| // This task prints the application id in this format: | ||
| // | ||
| // ApplicationId: com.example.my_id | ||
| // | ||
| // Format of the output of this task is used by `AndroidProject.getApplicationIdForVariant`. | ||
| private static void addTasksForPrintApplicationId(Project project) { | ||
| project.android.applicationVariants.all { variant -> | ||
| // Warning: The name of this task is used by `AndroidProject.getApplicationIdForVariant`. | ||
| project.tasks.register("print${variant.name.capitalize()}ApplicationId") { | ||
| description "Prints out application id for the given build variant of this Android project" | ||
| doLast { | ||
| println "ApplicationId: ${variant.applicationId}"; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Add a task that can be called on Flutter projects that prints app link domains of a build | ||
chunhtai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // variant. | ||
| // | ||
| // The app link domains refer to the host attributes of data tags in the apps' intent filters | ||
| // that support http/https schemes. See | ||
| // https://developer.android.com/guide/topics/manifest/intent-filter-element. | ||
| // | ||
| // This task prints app link domains in this format: | ||
| // | ||
| // Domain: domain.com | ||
| // Domain: another-domain.dev | ||
| // | ||
| // Format of the output of this task is used by `AndroidProject.getAppLinkDomainsForVariant`. | ||
| private static void addTasksForPrintAppLinkDomains(Project project) { | ||
| project.android.applicationVariants.all { variant -> | ||
| // Warning: The name of this task is used by `AndroidProject.getAppLinkDomainsForVariant`. | ||
| project.tasks.register("print${variant.name.capitalize()}AppLinkDomains") { | ||
| description "Prints out app links domain for the given build variant of this Android project" | ||
| variant.outputs.all { output -> | ||
| def processResources = output.hasProperty("processResourcesProvider") ? | ||
| output.processResourcesProvider.get() : output.processResources | ||
| dependsOn processResources.name | ||
| } | ||
| doLast { | ||
| variant.outputs.all { output -> | ||
| def processResources = output.hasProperty("processResourcesProvider") ? | ||
| output.processResourcesProvider.get() : output.processResources | ||
| def manifest = new XmlParser().parse(processResources.manifestFile) | ||
| manifest.application.activity.each { activity -> | ||
| // Find intent filters that have autoVerify = true and support http/https | ||
| // scheme. | ||
| activity.'intent-filter'.findAll { filter -> | ||
| def hasAutoVerify = filter.attributes().any { entry -> | ||
| return entry.key.getLocalPart() == "autoVerify" && entry.value | ||
| } | ||
| def hasHttpOrHttps = filter.data.any { data -> | ||
| data.attributes().any { entry -> | ||
| return entry.key.getLocalPart() == "scheme" && | ||
| (entry.value == "http" || entry.value == "https") | ||
| } | ||
| } | ||
| return hasAutoVerify && hasHttpOrHttps | ||
| }.each { appLinkIntent -> | ||
| // Print out the host attributes in data tags. | ||
| appLinkIntent.data.each { data -> | ||
| data.attributes().each { entry -> | ||
| if (entry.key.getLocalPart() == "host") { | ||
| println "Domain: ${entry.value}" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns a Flutter build mode suitable for the specified Android buildType. | ||
| * | ||
|
|
@@ -904,7 +983,11 @@ class FlutterPlugin implements Plugin<Project> { | |
| validateDeferredComponentsValue = project.property('validate-deferred-components').toBoolean() | ||
| } | ||
| addTaskForJavaVersion(project) | ||
| addTaskForPrintBuildVariants(project) | ||
| if(isFlutterAppProject()) { | ||
|
||
| addTaskForPrintBuildVariants(project) | ||
chunhtai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| addTasksForPrintApplicationId(project) | ||
| addTasksForPrintAppLinkDomains(project) | ||
| } | ||
| def targetPlatforms = getTargetPlatforms() | ||
| def addFlutterDeps = { variant -> | ||
| if (shouldSplitPerAbi()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright 2014 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:meta/meta.dart'; | ||
|
|
||
| /// A data class for app links related project settings. | ||
| /// | ||
| /// See https://developer.android.com/training/app-links. | ||
| @immutable | ||
| class AndroidAppLinkSettings { | ||
| const AndroidAppLinkSettings({ | ||
| required this.applicationId, | ||
| required this.domains, | ||
| }); | ||
|
|
||
| /// The application id of the android sub-project. | ||
| final String applicationId; | ||
|
|
||
| /// The associated web domains of the android sub-project. | ||
| final List<String> domains; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think according to https://developer.android.com/reference/tools/gradle-api/7.4/com/android/build/api/variant/ApplicationVariant#applicationId() this depends on some task running that will merge the manifests. That means this task depends on another task (possibly as simple as assembleVariant). Given this I think you should add a dependsOn block as defined here. https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:task_dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might actually want
variant.outputs.eachsee example here https://developer.android.com/build/gradle-tips#configure-dynamic-version-codes to print the applicationId.But I am not sure how task registration interacts differently if you use outputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I am trying to give good guidance here if you explore these things and they dont work you can ignore my comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it is not depending on any task, I ran it after a clean, and it still works. Also the application id is per applicationvariant I think? i didn't see a property on variantoutput for applicationID.