Skip to content

Commit 1d7f4a9

Browse files
authored
Fix build mode not propagated in android native asset build (#144550)
This fixes bug where build mode is hardcoded to debug while building native assets for Android. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [Data Driven Fixes]: https://github.com/flutter/flutter/wiki/Data-driven-Fixes
1 parent 6e7e4f3 commit 1d7f4a9

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

packages/flutter_tools/lib/src/build_system/targets/native_assets.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,13 @@ class NativeAssets extends Target {
314314
);
315315
final int targetAndroidNdkApi =
316316
int.parse(environment.defines[kMinSdkVersion] ?? minSdkVersion);
317+
final String? environmentBuildMode = environment.defines[kBuildMode];
318+
if (environmentBuildMode == null) {
319+
throw MissingDefineException(kBuildMode, name);
320+
}
321+
final BuildMode buildMode = BuildMode.fromCliName(environmentBuildMode);
317322
return buildNativeAssetsAndroid(
318-
buildMode: BuildMode.debug,
323+
buildMode: buildMode,
319324
projectUri: projectUri,
320325
yamlParentDirectory: environment.buildDir.uri,
321326
fileSystem: fileSystem,

packages/flutter_tools/test/general.shard/isolated/build_system/targets/native_assets_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void main() {
187187
await createPackageConfig(androidEnvironment);
188188
await fileSystem.file('libfoo.so').create();
189189

190-
final NativeAssetsBuildRunner buildRunner = FakeNativeAssetsBuildRunner(
190+
final FakeNativeAssetsBuildRunner buildRunner = FakeNativeAssetsBuildRunner(
191191
packagesWithNativeAssetsResult: <Package>[
192192
Package('foo', androidEnvironment.buildDir.uri)
193193
],
@@ -207,6 +207,7 @@ void main() {
207207
]),
208208
);
209209
await NativeAssets(buildRunner: buildRunner).build(androidEnvironment);
210+
expect(buildRunner.lastBuildMode, native_assets_cli.BuildMode.release);
210211
},
211212
);
212213
}

packages/flutter_tools/test/general.shard/isolated/fake_native_assets_build_runner.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
3636
int dryRunInvocations = 0;
3737
int hasPackageConfigInvocations = 0;
3838
int packagesWithNativeAssetsInvocations = 0;
39+
BuildMode? lastBuildMode;
3940

4041
@override
4142
Future<native_assets_builder.BuildResult> build({
@@ -49,6 +50,7 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
4950
IOSSdk? targetIOSSdk,
5051
}) async {
5152
buildInvocations++;
53+
lastBuildMode = buildMode;
5254
return buildResult;
5355
}
5456

0 commit comments

Comments
 (0)