Skip to content

Commit de72832

Browse files
authored
Fix frameworks added to bundle multiple times instead of lipo (#144688)
*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
1 parent 4d44662 commit de72832

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,15 @@ Target _getNativeTarget(DarwinArch darwinArch) {
148148
Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(List<Asset> nativeAssets) {
149149
final Set<String> alreadyTakenNames = <String>{};
150150
final Map<KernelAssetPath, List<Asset>> result = <KernelAssetPath, List<Asset>>{};
151+
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
151152
for (final Asset asset in nativeAssets) {
152-
final KernelAssetPath path = _targetLocationIOS(asset, alreadyTakenNames).path;
153+
// Use same target path for all assets with the same id.
154+
final KernelAssetPath path = idToPath[asset.id] ??
155+
_targetLocationIOS(
156+
asset,
157+
alreadyTakenNames,
158+
).path;
159+
idToPath[asset.id] = path;
153160
result[path] ??= <Asset>[];
154161
result[path]!.add(asset);
155162
}

packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,16 @@ Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(
175175
final Set<String> alreadyTakenNames = <String>{};
176176
final Map<KernelAssetPath, List<Asset>> result =
177177
<KernelAssetPath, List<Asset>>{};
178+
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
178179
for (final Asset asset in nativeAssets) {
179-
final KernelAssetPath path = _targetLocationMacOS(
180-
asset,
181-
absolutePath,
182-
alreadyTakenNames,
183-
).path;
180+
// Use same target path for all assets with the same id.
181+
final KernelAssetPath path = idToPath[asset.id] ??
182+
_targetLocationMacOS(
183+
asset,
184+
absolutePath,
185+
alreadyTakenNames,
186+
).path;
187+
idToPath[asset.id] = path;
184188
result[path] ??= <Asset>[];
185189
result[path]!.add(asset);
186190
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
1818
FakeNativeAssetsBuildRunner({
1919
this.hasPackageConfigResult = true,
2020
this.packagesWithNativeAssetsResult = const <Package>[],
21+
this.onBuild,
2122
this.dryRunResult = const FakeNativeAssetsBuilderResult(),
2223
this.buildResult = const FakeNativeAssetsBuilderResult(),
2324
CCompilerConfig? cCompilerConfigResult,
2425
CCompilerConfig? ndkCCompilerConfigResult,
2526
}) : cCompilerConfigResult = cCompilerConfigResult ?? CCompilerConfig(),
2627
ndkCCompilerConfigResult = ndkCCompilerConfigResult ?? CCompilerConfig();
2728

29+
final native_assets_builder.BuildResult Function(Target)? onBuild;
2830
final native_assets_builder.BuildResult buildResult;
2931
final native_assets_builder.DryRunResult dryRunResult;
3032
final bool hasPackageConfigResult;
@@ -51,7 +53,7 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
5153
}) async {
5254
buildInvocations++;
5355
lastBuildMode = buildMode;
54-
return buildResult;
56+
return onBuild?.call(target) ?? buildResult;
5557
}
5658

5759
@override

packages/flutter_tools/test/general.shard/isolated/ios/native_assets_test.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ void main() {
222222
'-create',
223223
'-output',
224224
'/build/native_assets/ios/bar.framework/bar',
225-
'libbar.dylib',
225+
'arm64/libbar.dylib',
226+
'x64/libbar.dylib',
226227
],
227228
),
228229
const FakeCommand(
@@ -253,7 +254,7 @@ void main() {
253254
await packageConfig.parent.create();
254255
await packageConfig.create();
255256
await buildNativeAssetsIOS(
256-
darwinArchs: <DarwinArch>[DarwinArch.arm64],
257+
darwinArchs: <DarwinArch>[DarwinArch.arm64, DarwinArch.x86_64],
257258
environmentType: EnvironmentType.simulator,
258259
projectUri: projectUri,
259260
buildMode: BuildMode.debug,
@@ -263,13 +264,13 @@ void main() {
263264
packagesWithNativeAssetsResult: <Package>[
264265
Package('bar', projectUri),
265266
],
266-
buildResult: FakeNativeAssetsBuilderResult(
267+
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
267268
assets: <Asset>[
268269
Asset(
269270
id: 'package:bar/bar.dart',
270271
linkMode: LinkMode.dynamic,
271-
target: native_assets_cli.Target.iOSArm64,
272-
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
272+
target: target,
273+
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
273274
),
274275
],
275276
),
@@ -278,8 +279,8 @@ void main() {
278279
expect(
279280
(globals.logger as BufferLogger).traceText,
280281
stringContainsInOrder(<String>[
281-
'Building native assets for [ios_arm64] debug.',
282-
'Building native assets for [ios_arm64] done.',
282+
'Building native assets for [ios_arm64, ios_x64] debug.',
283+
'Building native assets for [ios_arm64, ios_x64] done.',
283284
]),
284285
);
285286
expect(

packages/flutter_tools/test/general.shard/isolated/macos/native_assets_test.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ void main() {
259259
'-create',
260260
'-output',
261261
dylibPath,
262-
'libbar.dylib',
262+
'arm64/libbar.dylib',
263+
'x64/libbar.dylib',
263264
],
264265
),
265266
if (!flutterTester)
@@ -291,7 +292,7 @@ void main() {
291292
await packageConfig.parent.create();
292293
await packageConfig.create();
293294
final (Uri? nativeAssetsYaml, _) = await buildNativeAssetsMacOS(
294-
darwinArchs: <DarwinArch>[DarwinArch.arm64],
295+
darwinArchs: <DarwinArch>[DarwinArch.arm64, DarwinArch.x86_64],
295296
projectUri: projectUri,
296297
buildMode: BuildMode.debug,
297298
fileSystem: fileSystem,
@@ -300,13 +301,13 @@ void main() {
300301
packagesWithNativeAssetsResult: <Package>[
301302
Package('bar', projectUri),
302303
],
303-
buildResult: FakeNativeAssetsBuilderResult(
304+
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
304305
assets: <Asset>[
305306
Asset(
306307
id: 'package:bar/bar.dart',
307308
linkMode: LinkMode.dynamic,
308-
target: native_assets_cli.Target.macOSArm64,
309-
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
309+
target: target,
310+
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
310311
),
311312
],
312313
),
@@ -315,8 +316,8 @@ void main() {
315316
expect(
316317
(globals.logger as BufferLogger).traceText,
317318
stringContainsInOrder(<String>[
318-
'Building native assets for [macos_arm64] debug.',
319-
'Building native assets for [macos_arm64] done.',
319+
'Building native assets for [macos_arm64, macos_x64] debug.',
320+
'Building native assets for [macos_arm64, macos_x64] done.',
320321
]),
321322
);
322323
expect(

0 commit comments

Comments
 (0)