Skip to content

Commit 60f315d

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #828 from NativeScript/jasssonpet/do-not-embed-static-frameworks
Do not embed static frameworks
2 parents 2c25a53 + 549597e commit 60f315d

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

lib/services/ios-project-service.ts

+23-12
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,30 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
186186

187187
public addLibrary(libraryPath: string): IFuture<void> {
188188
return (() => {
189-
this.validateDynamicFramework(libraryPath).wait();
189+
this.validateFramework(libraryPath).wait();
190190

191191
let targetPath = path.join("lib", this.platformData.normalizedPlatformName);
192192
let fullTargetPath = path.join(this.$projectData.projectDir, targetPath);
193193
this.$fs.ensureDirectoryExists(fullTargetPath).wait();
194194
shell.cp("-R", libraryPath, fullTargetPath);
195195

196196
let project = this.createPbxProj();
197+
198+
let frameworkName = path.basename(libraryPath, path.extname(libraryPath));
199+
let frameworkBinaryPath = path.join(libraryPath, frameworkName);
200+
let isDynamic = _.contains(this.$childProcess.exec(`otool -Vh ${frameworkBinaryPath}`).wait(), " DYLIB ");
201+
202+
let frameworkAddOptions: xcode.FrameworkOptions = { customFramework: true };
203+
204+
if(isDynamic) {
205+
frameworkAddOptions["embed"] = true;
206+
project.updateBuildProperty("IPHONEOS_DEPLOYMENT_TARGET", "8.0");
207+
this.$logger.info("The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks.");
208+
}
209+
197210
let frameworkPath = this.getFrameworkRelativePath(libraryPath);
198-
project.addFramework(frameworkPath, { customFramework: true, embed: true });
199-
project.updateBuildProperty("IPHONEOS_DEPLOYMENT_TARGET", "8.0");
211+
project.addFramework(frameworkPath, frameworkAddOptions);
200212
this.savePbxProj(project).wait();
201-
this.$logger.info("The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks.");
202213
}).future<void>()();
203214
}
204215

@@ -305,15 +316,15 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
305316
public preparePluginNativeCode(pluginData: IPluginData): IFuture<void> {
306317
return (() => {
307318
let pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
308-
this.prepareDynamicFrameworks(pluginPlatformsFolderPath, pluginData).wait();
319+
this.prepareFrameworks(pluginPlatformsFolderPath, pluginData).wait();
309320
this.prepareCocoapods(pluginPlatformsFolderPath).wait();
310321
}).future<void>()();
311322
}
312323

313324
public removePluginNativeCode(pluginData: IPluginData): IFuture<void> {
314325
return (() => {
315326
let pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
316-
this.removeDynamicFrameworks(pluginPlatformsFolderPath, pluginData).wait();
327+
this.removeFrameworks(pluginPlatformsFolderPath, pluginData).wait();
317328
this.removeCocoapods(pluginPlatformsFolderPath).wait();
318329
}).future<void>()();
319330
}
@@ -343,7 +354,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
343354
}).future<void>()();
344355
}
345356

346-
private getAllDynamicFrameworksForPlugin(pluginData: IPluginData): IFuture<string[]> {
357+
private getAllFrameworksForPlugin(pluginData: IPluginData): IFuture<string[]> {
347358
let filterCallback = (fileName: string, pluginPlatformsFolderPath: string) => path.extname(fileName) === ".framework";
348359
return this.getAllNativeLibrariesForPlugin(pluginData, IOSProjectService.IOS_PLATFORM_NAME, filterCallback);
349360
}
@@ -352,7 +363,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
352363
return path.join(this.$npmInstallationManager.getCachedPackagePath(this.platformData.frameworkPackageName, version), constants.PROJECT_FRAMEWORK_FOLDER_NAME, util.format("%s.xcodeproj", IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER), "project.pbxproj");
353364
}
354365

355-
private validateDynamicFramework(libraryPath: string): IFuture<void> {
366+
private validateFramework(libraryPath: string): IFuture<void> {
356367
return (() => {
357368
let infoPlistPath = path.join(libraryPath, "Info.plist");
358369
if (!this.$fs.exists(infoPlistPath).wait()) {
@@ -383,9 +394,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
383394
}).future<void>()();
384395
}
385396

386-
private prepareDynamicFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
397+
private prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
387398
return (() => {
388-
_.each(this.getAllDynamicFrameworksForPlugin(pluginData).wait(), fileName => this.addLibrary(path.join(pluginPlatformsFolderPath, fileName)).wait());
399+
_.each(this.getAllFrameworksForPlugin(pluginData).wait(), fileName => this.addLibrary(path.join(pluginPlatformsFolderPath, fileName)).wait());
389400
}).future<void>()();
390401
}
391402

@@ -400,11 +411,11 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
400411
}).future<void>()();
401412
}
402413

403-
private removeDynamicFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
414+
private removeFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
404415
return (() => {
405416
let project = this.createPbxProj();
406417

407-
_.each(this.getAllDynamicFrameworksForPlugin(pluginData).wait(), fileName => {
418+
_.each(this.getAllFrameworksForPlugin(pluginData).wait(), fileName => {
408419
let fullFrameworkPath = path.join(pluginPlatformsFolderPath, fileName);
409420
let relativeFrameworkPath = this.getFrameworkRelativePath(fullFrameworkPath);
410421
project.removeFramework(relativeFrameworkPath, { customFramework: true, embed: true });

0 commit comments

Comments
 (0)