You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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.
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:
/* 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.
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.
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
{
Activity
akame commentedon Dec 29, 2015
@hartman Have you fix this problem?I add some code,and it works.
hartman commentedon Dec 29, 2015
@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.
jasperblues commentedon Dec 30, 2015
@hartman Did you use XCSourceFile or another approach? We can either update docs with working solution or provide a dedicated method.
hartman commentedon Dec 30, 2015
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:
Buildkey entries:
These are then referenced from two buildphases
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.
assuming your framework is 'somewhere' inside your project dir.
hartman commentedon Dec 30, 2015
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.
akame commentedon Dec 31, 2015
I add some Code
_in XCGroup.m_*
[self addFramework:framework];
XCSourceFile *embedded = (XCSourceFile *) [self memberWithDisplayName:[framework fileName]];
[self addEmbeddedSourceFile:embedded toTargets: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
{
}
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"];
}
[self flagMembersAsDirty];
}
***_in XCSourceFile.m_
(void)becomeEmbedded
{
if (_type == Framework) {
NSMutableDictionary *sourceBuildFile = [NSMutableDictionary dictionary];
sourceBuildFile[@"isa"] = [NSString xce_stringFromMemberType:PBXBuildFileType];
sourceBuildFile[@"fileRef"] = _key;
}
}
(NSString *)embeddedKey
{
if (_embeddedKey == nil) {
[[_project objects] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
if ([[obj valueForKey:@"isa"] xce_hasBuildFileType]) {
}
return [_embeddedKey copy];
}
akame commentedon Dec 31, 2015
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]) {
}
return [_buildFileKey copy];
}
_XCSourceFile.m_
akame commentedon Dec 31, 2015
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"];
}
@hartman
a83988029 commentedon May 19, 2016
@akame thanks! it works.
why not commit to the project to make it better.