Skip to content

feat(flutter_tools): upgrade flutter.gradle to update shorebird.yaml when flavors are used. #6

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

Merged
merged 1 commit into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/flutter_tools/gradle/flutter.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.bundling.Jar
import org.gradle.internal.os.OperatingSystem
import org.gradle.util.VersionNumber
import org.yaml.snakeyaml.Yaml

/** For apps only. Provides the flutter extension used in app/build.gradle. */
class FlutterExtension {
Expand Down Expand Up @@ -63,6 +64,7 @@ buildscript {
dependencies {
/* When bumping, also update ndkVersion above. */
classpath 'com.android.tools.build:gradle:7.3.0'
classpath group: 'org.yaml', name: 'snakeyaml', version: '2.0'
}
}

Expand Down Expand Up @@ -975,6 +977,23 @@ class FlutterPlugin implements Plugin<Project> {
return
}
Task copyFlutterAssetsTask = addFlutterDeps(variant)
copyFlutterAssetsTask.doLast {
if (variant.flavorName != null && !variant.flavorName.isEmpty()) {
def outputDir = copyFlutterAssetsTask.destinationDir
def shorebirdYamlFile = new File("${outputDir}/flutter_assets/shorebird.yaml")
def flavor = variant.flavorName
def shorebirdYaml = new Yaml().load(shorebirdYamlFile.text)
def flavorAppId = shorebirdYaml['app_id'][flavor]
if (flavorAppId == null) {
throw new GradleException("Cannot find app_id for ${flavor} in shorebird.yaml")
}
def content = 'app_id: ' + flavorAppId + '\n';
if (shorebirdYaml.containsKey('base_url')) {
content += 'base_url: ' + shorebirdYaml['base_url'] + '\n';
}
shorebirdYamlFile.write(content)
}
}
def variantOutput = variant.outputs.first()
def processResources = variantOutput.hasProperty("processResourcesProvider") ?
variantOutput.processResourcesProvider.get() : variantOutput.processResources
Expand Down