Comments (9)
@hartman Have you fix this problem?I add some code,and it works.
from xcodeeditor.
@akame no, not really. The issues I encountered were:
1: An embedded framework is a source file that is in TWO buildphases.
2: Because of this, the XSourceFile also has to have TWO build file entries, instead of what the framework assumes (one)
3: An embedded framework has specific build settings in only one of the build phases.
from xcodeeditor.
@hartman Did you use XCSourceFile or another approach? We can either update docs with working solution or provide a dedicated method.
from xcodeeditor.
I hacked something up with hardcoded modifiers etc, but it's not really usable for anyone else due to the hardcoded assumptions I make and unfortunately it doesn't seem like I have any time available soon to fix it 'properly'.
The proper way would be to move the 'build file' identifier logic that is in XSourceFile (see the buildFileKey property) into the buildPhases logic of XCTarget instead, or even to make build phases and their keys a separate class.
The build fileref entries also need their own build attribute properties, since embedded frameworks carry the attributes CodeSignOnCopy, RemoveHeadersOnCopy
. (This is similar to where weak linking attribute and other build settings for other types of build files usually reside).
Some relevant fragments from an actual project file:
Sourcefile entry:
077F993C1B1C42ED0096BDE8 /* MyEmbedded.framework */ = {
isa = PBXFileReference;
fileEncoding = 4;
lastKnownFileType = wrapper.framework;
path = MyEmbedded.framework;
sourceTree = "<group>";
};
Buildkey entries:
077F99401B1C43610096BDE8 /* MyEmbedded.framework in Frameworks */ = {
isa = PBXBuildFile;
fileRef = 077F993C1B1C42ED0096BDE8 /* MyEmbedded.framework */;
};
077F99411B1C43610096BDE8 /* MyEmbedded.framework in Embed Frameworks */ = {
isa = PBXBuildFile;
fileRef = 077F993C1B1C42ED0096BDE8 /* MyEmbedded.framework */;
settings = {
ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, );
};
};
These are then referenced from two buildphases
/* Begin PBXFrameworksBuildPhase section */
4500D2DD132F708D00C21112 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
45A4897114C8486100450DF1 /* AudioToolbox.framework in Frameworks */,
[...]
58243472b6c71df1eb70ab08 /* libc++.dylib in Frameworks */,
889e5236762d6dd5969d7d7d /* libiconv.dylib in Frameworks */,
077F99401B1C43610096BDE8 /* MyEmbedded.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXCopyFilesBuildPhase section */
077F99441B1C43610096BDE8 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
077F99411B1C43610096BDE8 /* MyEmbedded.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
Note how EmbedFrameworks is a rather generic CopyFilesBuildPhase, with the distinguishing feature of it being named "Embed Frameworks", which is... well if I were Apple, I think I'd simply introduced a new PBX build phase class for that, instead of relying on a strcmp to a modifiable name... Also this build phase is not present by default in Xcode projects, so you need to create it manually, which is another problem, since that is another thing that isn't implemented in XcodeEditor yet.
Oh, and you have to add this to your build configuration.
FRAMEWORK_SEARCH_PATHS = (
"$(PROJECT_DIR)/**",
);
assuming your framework is 'somewhere' inside your project dir.
from xcodeeditor.
Oh, and you need to figure out how you would be able to distinguish between an old style static framework and a embedded framework, because they require different 'addMember' strategies and I haven't really been able to find a good/reliable/efficient way to (on the fly) distinguish the two. If anyone has any good tips for that, love to hear them.
from xcodeeditor.
I add some Code
_in XCGroup.m_*
- (void)addEmbeddedFramework:(XCFrameworkDefinition *)framework toTargets:(NSArray<XCTarget *> *)targets{
[self addFramework:framework];
XCSourceFile *embedded = (XCSourceFile *) [self memberWithDisplayName:[framework fileName]];
[self addEmbeddedSourceFile:embedded toTargets:targets];
} - (void)addEmbeddedSourceFile:(XCSourceFile *)sourceFile toTargets:(NSArray *)targets
{
for (XCTarget *target in targets) {
[target addMember:sourceFile];
[target addEmbedded:sourceFile];
}
}
****in XCTarget.m ***
-
(void)addEmbedded:(XCSourceFile*)member
{
[member becomeEmbedded];NSMutableDictionary* target = [NSMutableDictionary dictionaryWithDictionary:[[_project objects] objectForKey:_key]];
BOOL hasEmbeddedConfiguration = NO;
for (NSString* buildPhaseKey in [target objectForKey:@"buildPhases"])
{
NSMutableDictionary* buildPhase = [[_project objects] objectForKey:buildPhaseKey];
if ([[buildPhase valueForKey:@"isa"] xce_asMemberType] == PBXCopyFilesBuildPhaseType) //targer have already use embedded
{NSMutableArray* files = [buildPhase objectForKey:@"files"]; if (![files containsObject:[member embeddedKey]]) { [files addObject:[member embeddedKey]]; } [buildPhase setObject:files forKey:@"files"]; hasEmbeddedConfiguration = YES; }
}
if (!hasEmbeddedConfiguration) { // target never use embedded before
NSMutableDictionary *embeddedConfig = [NSMutableDictionary dictionary];
[embeddedConfig setObject:@"PBXCopyFilesBuildPhase" forKey:@"isa"];
[embeddedConfig setObject:@"2147483647" forKey:@"buildActionMask"];
[embeddedConfig setObject:@"" forKey:@"dstPath"];
[embeddedConfig setObject:@"10" forKey:@"dstSubfolderSpec"];
[embeddedConfig setObject:@"Embed Frameworks" forKey:@"name"];
[embeddedConfig setObject:@"0" forKey:@"runOnlyForDeploymentPostprocessing"];
[embeddedConfig setObject:@[[member embeddedKey]] forKey:@"files"];NSString *embeddedKey = [[XCKeyBuilder forItemNamed:[_name stringByAppendingString:@".EmbedFrameworks"]] build]; NSMutableArray *buildPhases = [NSMutableArray arrayWithArray:[target objectForKey:@"buildPhases"]]; [buildPhases addObject:embeddedKey]; [target setObject:buildPhases forKey:@"buildPhases"]; [[_project objects] setObject:target forKey:_key]; [[_project objects] setObject:embeddedConfig forKey:embeddedKey];
}
[self flagMembersAsDirty];
}
***_in XCSourceFile.m_
-
(void)becomeEmbedded
{
if (_type == Framework) {
NSMutableDictionary *sourceBuildFile = [NSMutableDictionary dictionary];
sourceBuildFile[@"isa"] = [NSString xce_stringFromMemberType:PBXBuildFileType];
sourceBuildFile[@"fileRef"] = _key;NSDictionary *dict = [NSDictionary dictionaryWithObject:@[@"CodeSignOnCopy",@"RemoveHeadersOnCopy"] forKey:@"ATTRIBUTES"]; sourceBuildFile[@"settings"] = dict; NSString *buildFileKey = [[XCKeyBuilder forItemNamed:[_name stringByAppendingString:@".embedded"]] build]; [_project objects][buildFileKey] = sourceBuildFile;
}
} -
(NSString *)embeddedKey
{
if (_embeddedKey == nil) {
[[_project objects] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
if ([[obj valueForKey:@"isa"] xce_hasBuildFileType]) {if ([[obj valueForKey:@"fileRef"] isEqualToString:_key]) { if ([[obj valueForKey:@"settings"] allKeys].count > 0) { NSDictionary *settings = [obj valueForKey:@"settings"]; [settings enumerateKeysAndObjectsUsingBlock:^(id _Nonnull settingKey, id _Nonnull settingobj, BOOL * _Nonnull settingStop) { if (([settingobj containsObject:@"CodeSignOnCopy"] && [settingobj containsObject:@"RemoveHeadersOnCopy"])) { _embeddedKey = [key copy]; NSLog(@"there is a embedded framework"); } }]; } } } }];
}
return [_embeddedKey copy];
}
from xcodeeditor.
Of course we should change buildFileKey function in XCSourceFile.m
_XCSourceFile.m_
-
(NSString *)buildFileKey
{
if (_buildFileKey == nil) {
[[_project objects] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
if ([[obj valueForKey:@"isa"] xce_hasBuildFileType]) {
if ([[obj valueForKey:@"fileRef"] isEqualToString:_key]) {if ([[obj valueForKey:@"settings"] allKeys].count > 0) { NSDictionary *settings = [obj valueForKey:@"settings"]; [settings enumerateKeysAndObjectsUsingBlock:^(id _Nonnull settingKey, id _Nonnull settingobj, BOOL * _Nonnull settingStop) { if (!([settingobj containsObject:@"CodeSignOnCopy"] && [settingobj containsObject:@"RemoveHeadersOnCopy"])) { _buildFileKey = [key copy]; } }]; }else{ _buildFileKey = [key copy]; } } } }];
}
return [_buildFileKey copy];
}
_XCSourceFile.m_
from xcodeeditor.
At last I change XcodeBuildConfiguration:
for (NSString *configName in [target configurations]) { //Debug Release
XCProjectBuildConfig *config = [target configurationWithName:configName];
NSString *ldRunPath = @"$(inherited) @executable_path/Frameworks";
[config addOrReplaceSetting:ldRunPath forKey:@"LD_RUNPATH_SEARCH_PATHS"];
}
from xcodeeditor.
@akame thanks! it works.
why not commit to the project to make it better.
from xcodeeditor.
Related Issues (20)
- addframework failed in xcode7 HOT 11
- ESA.Sales.Foobar.xib: iOS xibs do not support target device type "mac" HOT 1
- Linker Error because of duplicate symbols HOT 3
- Update Compile Sources HOT 4
- xcconfig not work in project and target base configuration!
- how can i remove an existing xxx.framework(not imported from apple's libraries) from my project HOT 4
- Carthage: Dependency "XcodeEditor" has no shared framework schemes
- Add file to dynamic framework target Public/Private/Project Build Phases > Headers?
- Make scheme shared
- removeResourceWithKey and removeMemberWithKey need documentation
- XcodeEditor does not handle Emoji in build phase names well HOT 14
- [Question] Does XCodeEditor support sorting targets in alphabetical order?
- feature - determine project / name directory path / project file from key window HOT 4
- Doesn't get all the XCBuildConfiguration's in the file HOT 2
- "Project file of type file.storyboard can't become a build file." HOT 1
- Support for Copy Bundle Phases HOT 6
- Create new Target & Scheme HOT 1
- EXC_BAD_ACCESS from xce_stringFromMemberType HOT 1
- how to add some .strings files to project? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xcodeeditor.