@@ -26,6 +26,7 @@ import org.gradle.api.tasks.TaskAction
2626import org.gradle.api.tasks.bundling.Jar
2727import org.gradle.internal.os.OperatingSystem
2828import org.gradle.util.VersionNumber
29+ import org.yaml.snakeyaml.Yaml
2930
3031/* * For apps only. Provides the flutter extension used in app/build.gradle. */
3132class FlutterExtension {
@@ -63,6 +64,7 @@ buildscript {
6364 dependencies {
6465 /* When bumping, also update ndkVersion above. */
6566 classpath ' com.android.tools.build:gradle:7.3.0'
67+ classpath group : ' org.yaml' , name : ' snakeyaml' , version : ' 2.0'
6668 }
6769}
6870
@@ -975,6 +977,23 @@ class FlutterPlugin implements Plugin<Project> {
975977 return
976978 }
977979 Task copyFlutterAssetsTask = addFlutterDeps(variant)
980+ copyFlutterAssetsTask. doLast {
981+ if (variant. flavorName != null && ! variant. flavorName. isEmpty()) {
982+ def outputDir = copyFlutterAssetsTask. destinationDir
983+ def shorebirdYamlFile = new File (" ${ outputDir} /flutter_assets/shorebird.yaml" )
984+ def flavor = variant. flavorName
985+ def shorebirdYaml = new Yaml (). load(shorebirdYamlFile. text)
986+ def flavorAppId = shorebirdYaml[' app_id' ][flavor]
987+ if (flavorAppId == null ) {
988+ throw new GradleException (" Cannot find app_id for ${ flavor} in shorebird.yaml" )
989+ }
990+ def content = ' app_id: ' + flavorAppId + ' \n ' ;
991+ if (shorebirdYaml. containsKey(' base_url' )) {
992+ content + = ' base_url: ' + shorebirdYaml[' base_url' ] + ' \n ' ;
993+ }
994+ shorebirdYamlFile. write(content)
995+ }
996+ }
978997 def variantOutput = variant. outputs. first()
979998 def processResources = variantOutput. hasProperty(" processResourcesProvider" ) ?
980999 variantOutput. processResourcesProvider. get() : variantOutput. processResources
0 commit comments