Skip to content

Commit

Permalink
ios: support libnode .xcframework format
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecbernardo committed Aug 15, 2021
1 parent 94022b3 commit 7951c0c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
26 changes: 0 additions & 26 deletions install/hooks/ios/after-plugin-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,6 @@ find "$CODESIGNING_FOLDER_PATH/www/nodejs-project/" -name "*.framework" -type d
);
}

//Adds a build phase to remove the x64 strips from the NodeMobile framework. Needed for correct App Store submission.
var removeSimulatorArchsBuildPhaseName = 'Remove NodeJS Mobile Framework Simulator Strips';
var removeSimulatorArchsBuildPhaseScript = `
set -e
FRAMEWORK_BINARY_PATH="$TARGET_BUILD_DIR/$FRAMEWORKS_FOLDER_PATH/NodeMobile.framework/NodeMobile"
FRAMEWORK_STRIPPED_PATH="$FRAMEWORK_BINARY_PATH-strip"
if [ "$PLATFORM_NAME" != "iphonesimulator" ]; then
if $(lipo "$FRAMEWORK_BINARY_PATH" -verify_arch "x86_64") ; then
lipo -output "$FRAMEWORK_STRIPPED_PATH" -remove "x86_64" "$FRAMEWORK_BINARY_PATH"
rm "$FRAMEWORK_BINARY_PATH"
mv "$FRAMEWORK_STRIPPED_PATH" "$FRAMEWORK_BINARY_PATH"
echo "Removed simulator strip from NodeMobile.framework"
fi
fi
`
var removeSimulatorArchsBuildPhase = xcodeProject.buildPhaseObject('PBXShellScriptBuildPhase', removeSimulatorArchsBuildPhaseName, firstTargetUUID);
if (!removeSimulatorArchsBuildPhase) {
xcodeProject.addBuildPhase(
[],
'PBXShellScriptBuildPhase',
removeSimulatorArchsBuildPhaseName,
firstTargetUUID,
{ shellPath: '/bin/sh', shellScript: removeSimulatorArchsBuildPhaseScript }
);
}

// Write the changes into the Xcode project.
fs.writeFileSync(pbxprojPath, xcodeProject.writeSync());

Expand Down
2 changes: 1 addition & 1 deletion install/hooks/ios/before-plugin-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var targz2 = require('tar.gz2');

const nodeProjectFolder = 'www/nodejs-project';
const nodeMobileFolderPath = 'plugins/nodejs-mobile-cordova/libs/ios/nodemobile/';
const nodeMobileFileName = 'NodeMobile.framework';
const nodeMobileFileName = 'NodeMobile.xcframework';
const nodeMobileFilePath = nodeMobileFolderPath + nodeMobileFileName;
const zipFileName = nodeMobileFileName + '.tar.zip';
const zipFilePath = nodeMobileFolderPath + zipFileName
Expand Down
21 changes: 21 additions & 0 deletions install/hooks/ios/fix-xcframework-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var path = require('path');
var fs = require('fs');

module.exports = function(context) {
// Require the iOS platform Api to get the Xcode .pbxproj path.
var iosPlatformPath = path.join(context.opts.projectRoot, 'platforms', 'ios');
var iosAPI = require(path.join(iosPlatformPath, 'cordova', 'Api'));
var iosAPIInstance = new iosAPI();
var pbxprojPath = iosAPIInstance.locations.pbxproj;
var rootIosProjDir = iosAPIInstance.locations.root;
var cordovaProjPath = iosAPIInstance.locations.xcodeCordovaProj;
var xcFrameworkPath = path.join(cordovaProjPath, 'Plugins', 'nodejs-mobile-cordova', 'NodeMobile.xcframework');
var relativeXcFrameworkPath = path.relative(rootIosProjDir, xcFrameworkPath);

// Patch the project file to fix a .xcframework include error.
let pbxProjContents = fs.readFileSync(pbxprojPath).toString();
pbxProjContents = pbxProjContents.replace('path = libs/ios/nodemobile/NodeMobile.xcframework', `path = "${relativeXcFrameworkPath}"`);
pbxProjContents = pbxProjContents.replace('path = "libs/ios/nodemobile/NodeMobile.xcframework"', `path = "${relativeXcFrameworkPath}"`);
fs.writeFileSync(pbxprojPath, pbxProjContents);

}
8 changes: 6 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<hook type="before_plugin_install" src="install/hooks/ios/before-plugin-install.js" />
<hook type="after_plugin_install" src="install/hooks/ios/after-plugin-install.js" />
<hook type="before_plugin_uninstall" src="install/hooks/ios/before-plugin-uninstall.js" />
<hook type="after_platform_add" src="install/hooks/ios/fix-xcframework-path.js" />
<hook type="after_plugin_add" src="install/hooks/ios/fix-xcframework-path.js" />
<hook type="after_plugin_install" src="install/hooks/ios/fix-xcframework-path.js" />
<hook type="after_prepare" src="install/hooks/ios/fix-xcframework-path.js" />
<hook type="after_prepare" src="install/hooks/both/after-prepare-patch-npm-packages.js" />
<hook type="after_prepare" src="install/hooks/both/after-prepare-native-modules-preference.js" />

Expand All @@ -48,8 +52,8 @@

<asset src="install/nodejs-mobile-cordova-assets" target="nodejs-mobile-cordova-assets" />

<framework src="libs/ios/nodemobile/NodeMobile.framework" custom="true" embed="true" />
<framework src="libs/ios/nodemobile/NodeMobile.framework" />
<framework src="libs/ios/nodemobile/NodeMobile.xcframework" custom="true" embed="true" />
<framework src="libs/ios/nodemobile/NodeMobile.xcframework" />

</platform>

Expand Down

0 comments on commit 7951c0c

Please sign in to comment.