Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 72acccc

Browse files
author
Chris Yang
committed
fix
1 parent ee31bf1 commit 72acccc

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
FLUTTER_ASSERT_ARC
1010

11-
const NSString* kDefaultAssetPath = @"Frameworks/App.framework/flutter_assets";
12-
static NSString* GetFlutterAssetPathFromBundle(NSBundle* bundle);
11+
NSString* kDefaultAssetPath = @"Frameworks/App.framework/flutter_assets";
12+
static NSString* GetFlutterAssetsPathFromBundle(NSBundle* bundle, NSString* relativeAssetsPath);
1313

1414
NSBundle* FLTFrameworkBundleInternal(NSString* flutterFrameworkBundleID, NSURL* searchURL) {
1515
NSDirectoryEnumerator<NSURL*>* frameworkEnumerator = [NSFileManager.defaultManager
@@ -55,22 +55,22 @@
5555
}
5656

5757
NSString* FLTAssetPath(NSBundle* bundle) {
58-
return [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"] ?: kDefaultAssetPath;
58+
return [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"] ?: relativeAssetsPath;
5959
}
6060

6161
NSString* FLTAssetsPathFromBundle(NSBundle* bundle) {
62-
NSString* flutterAssetsPath = GetFlutterAssetPathFromBundle(bundle);
62+
NSString* relativeAssetsPath = FLTAssetPath(bundle);
63+
NSString* flutterAssetsPath = GetFlutterAssetsPathFromBundle(bundle, relativeAssetsPath);
6364
if (flutterAssetsPath.length == 0) {
64-
flutterAssetsPath = GetFlutterAssetPathFromBundle(NSBundle.mainBundle);
65+
flutterAssetsPath = GetFlutterAssetsPathFromBundle(NSBundle.mainBundle, relativeAssetsPath);
6566
}
6667
return flutterAssetsPath;
6768
}
6869

69-
static NSString* GetFlutterAssetPathFromBundle(NSBundle* bundle) {
70-
NSString* flutterAssetsPath = FLTAssetPath(bundle);
70+
static NSString* GetFlutterAssetsPathFromBundle(NSBundle* bundle, NSString* relativeAssetsPath) {
7171
// Use the raw path solution so that asset path can be returned from unloaded bundles.
7272
// See https://github.com/flutter/engine/pull/46073
73-
NSString* assetsPath = [bundle pathForResource:flutterAssetsPath ofType:nil];
73+
NSString* assetsPath = [bundle pathForResource:relativeAssetsPath ofType:nil];
7474
if (assetsPath.length == 0) {
7575
// In app extension, using full relative path (kDefaultAssetPath)
7676
// returns nil when the app bundle is not loaded. Try to use

shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ - (void)testFLTAssetsURLFromBundle {
9797
NSString* path = FLTAssetsPathFromBundle(mockBundle);
9898
XCTAssertEqualObjects(path, @"path/to/foo/assets");
9999
}
100+
{
101+
// Found asset path in info.plist, is not overriden by main bundle
102+
id mockBundle = OCMClassMock([NSBundle class]);
103+
id mockMainBundle = OCMClassMock(NSBundle.mainBundle);
104+
OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets");
105+
OCMStub([mockMainBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(nil);
106+
NSString* resultAssetsPath = @"path/to/foo/assets";
107+
OCMStub([mockBundle pathForResource:@"foo/assets" ofType:nil]).andReturn(resultAssetsPath);
108+
NSString* path = FLTAssetsPathFromBundle(mockBundle);
109+
XCTAssertEqualObjects(path, @"path/to/foo/assets");
110+
}
100111
{
101112
// No asset path in info.plist, defaults to main bundle
102113
id mockBundle = OCMClassMock([NSBundle class]);

0 commit comments

Comments
 (0)