Skip to content

Commit 02d5286

Browse files
authored
[iOS] fix hot restart with native assets (#148752)
Fixes flutter/flutter#148687 Adds support for running the hot restart and reload integration test on iOS simulator. ## 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 `///`). - [ ] 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 c14d55c commit 02d5286

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

dev/devicelab/bin/tasks/native_assets_ios_simulator.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ Future<void> main() async {
1212
await task(() async {
1313
deviceOperatingSystem = DeviceOperatingSystem.ios;
1414
String? simulatorDeviceId;
15+
TaskResult res = TaskResult.success(null);
1516
try {
1617
await testWithNewIOSSimulator(
1718
'TestNativeAssetsSim',
1819
(String deviceId) async {
1920
simulatorDeviceId = deviceId;
20-
await createNativeAssetsTest(
21+
res = await createNativeAssetsTest(
2122
deviceIdOverride: deviceId,
2223
isIosSimulator: true,
2324
)();
@@ -26,6 +27,6 @@ Future<void> main() async {
2627
} finally {
2728
await removeIOSSimulator(simulatorDeviceId);
2829
}
29-
return TaskResult.success(null);
30+
return res;
3031
});
3132
}

dev/devicelab/lib/tasks/native_assets_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ TaskFunction createNativeAssetsTest({
5454
];
5555
int transitionCount = 0;
5656
bool done = false;
57+
bool error = false;
5758

5859
await inDirectory<void>(exampleDirectory, () async {
5960
final int runFlutterResult = await runFlutter(
6061
options: options,
6162
onLine: (String line, Process process) {
63+
error |= line.contains('EXCEPTION CAUGHT BY WIDGETS LIBRARY');
64+
error |= line.contains("Invalid argument(s): Couldn't resolve native function 'sum'");
6265
if (done) {
6366
return;
6467
}
@@ -108,6 +111,9 @@ TaskFunction createNativeAssetsTest({
108111
'(expected $expectedNumberOfTransitions)',
109112
);
110113
}
114+
if (error) {
115+
return TaskResult.failure('Error during hot reload or hot restart.');
116+
}
111117
return TaskResult.success(null);
112118
});
113119
if (buildModeResult.failed) {

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,23 @@ Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(
186186
Map<AssetImpl, KernelAsset> _assetTargetLocations(
187187
List<AssetImpl> nativeAssets) {
188188
final Set<String> alreadyTakenNames = <String>{};
189-
return <AssetImpl, KernelAsset>{
190-
for (final AssetImpl asset in nativeAssets)
191-
asset: _targetLocationIOS(asset, alreadyTakenNames),
192-
};
189+
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
190+
final Map<AssetImpl, KernelAsset> result = <AssetImpl, KernelAsset>{};
191+
for (final AssetImpl asset in nativeAssets) {
192+
final KernelAssetPath path = idToPath[asset.id] ??
193+
_targetLocationIOS(asset, alreadyTakenNames).path;
194+
idToPath[asset.id] = path;
195+
result[asset] = KernelAsset(
196+
id: (asset as NativeCodeAssetImpl).id,
197+
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
198+
path: path,
199+
);
200+
}
201+
return result;
193202
}
194203

195204
KernelAsset _targetLocationIOS(AssetImpl asset, Set<String> alreadyTakenNames) {
196-
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
205+
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
197206
final KernelAssetPath kernelAssetPath;
198207
switch (linkMode) {
199208
case DynamicLoadingSystemImpl _:

0 commit comments

Comments
 (0)