ios-jsc icon indicating copy to clipboard operation
ios-jsc copied to clipboard

Cannot build with XCFramework in plugin

Open ddfreiling opened this issue 5 years ago • 1 comments

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 6.3.3
  • Cross-platform modules: 6.3.2
  • iOS Runtime: 6.3.0
  • Android Runtime (if applicable):
  • Plugin(s): https://github.com/Notalib/nativescript-webview-ext/tree/ba57098ef56a846720febeb164324944a523a8b9

Describe the bug

A project with a plugin which includes a .XCFramework in its /platforms/ios can prepare just fine, but when you try to build it, it fails because of the strip-dynamic-framework-architectures.sh script, which does not seem to support XCFrameworks.

To Reproduce

tns create mydemo --ng tns plugin add @nota/nativescript-webview-ext@xcframework tns build ios

Expected behavior Expect that tns build does not try to strip out architectures from an .XCFramework from a plugin. https://github.com/NativeScript/ios-runtime/blob/master/build/project-template/internal/strip-dynamic-framework-architectures.sh should probably be updated to support .XCFramework libraries.

Sample project

See repro. Plugin source at https://github.com/Notalib/nativescript-webview-ext/tree/ba57098ef56a846720febeb164324944a523a8b9

Additional context

I added some debug logging to strip-dynamic-framework-architectures.sh and got this output. It seems it's trying to use lipo to remove the only architecture of a non-fat Framework inside an XCFramework.

==========================================
strip-dynamic-frameworks
- with path: /Users/b044554/code/tns-plugins/nativescript-webview-ext/demo/platforms/ios/build/Debug-iphonesimulator/demo.app/Frameworks
- valid archs: i386 x86_64
==========================================
Stripping frameworks in /Users/b044554/code/tns-plugins/nativescript-webview-ext/demo/platforms/ios/build/Debug-iphonesimulator/demo.app/Frameworks
- skip ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/_CodeSignature/CodeResources
- get arch for ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/NotaWebViewExt
- got Non-fat file: ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/NotaWebViewExt is architecture: x86_64
- skip ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/Headers/NotaWebViewExt-Swift.h
- skip ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/Headers/NotaWebViewExt.h
- skip ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/Modules/NotaWebViewExt.swiftmodule/x86_64-apple-ios-simulator.swiftinterface
- skip ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/Modules/NotaWebViewExt.swiftmodule/x86_64-apple-ios-simulator.swiftdoc
- skip ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/Modules/NotaWebViewExt.swiftmodule/x86_64.swiftdoc
- skip ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/Modules/NotaWebViewExt.swiftmodule/x86_64.swiftinterface
- skip ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/Modules/module.modulemap
- skip ./NotaWebViewExt.xcframework/ios-x86_64-simulator/NotaWebViewExt.framework/Info.plist
- skip ./NotaWebViewExt.xcframework/ios-arm64/NotaWebViewExt.framework/_CodeSignature/CodeResources
- get arch for ./NotaWebViewExt.xcframework/ios-arm64/NotaWebViewExt.framework/NotaWebViewExt
- got Non-fat file: ./NotaWebViewExt.xcframework/ios-arm64/NotaWebViewExt.framework/NotaWebViewExt is architecture: arm64
- remove arch arm64 in ./NotaWebViewExt.xcframework/ios-arm64/NotaWebViewExt.framework/NotaWebViewExt
fatal error: lipo: input file (./NotaWebViewExt.xcframework/ios-arm64/NotaWebViewExt.framework/NotaWebViewExt) must be a fat file when the -remove option is specified
Command PhaseScriptExecution failed with a nonzero exit code

ddfreiling avatar Jan 15 '20 15:01 ddfreiling

Hi @ddfreiling, I tried to reproduce the issue, but it seems not reproducible with Xcode 11.3. What is your version (please check with xcodebuild -version). I got the following output of the strip script:

Stripping frameworks in /Users/bektchiev/work/_scratch/mydemo/platforms/ios/build/Debug-iphonesimulator/mydemo.app/Frameworks
Architectures of ./NotaWebViewExt.framework/NotaWebViewExt: x86_64
Architectures of ./NativeScript.framework/NativeScript: i386 x86_64 armv7 arm64
Stripped ./NativeScript.framework/NativeScript of architectures: armv7 arm64
Code Signing ./NativeScript.framework/NativeScript with Identity -
/usr/bin/codesign --force --sign - --preserve-metadata=identifier,entitlements ./NativeScript.framework/NativeScript
./NativeScript.framework/NativeScript: replacing existing signature
Architectures of ./TNSWidgets.framework/TNSWidgets: i386 x86_64 armv7 arm64
Stripped ./TNSWidgets.framework/TNSWidgets of architectures: armv7 arm64
Code Signing ./TNSWidgets.framework/TNSWidgets with Identity -
/usr/bin/codesign --force --sign - --preserve-metadata=identifier,entitlements ./TNSWidgets.framework/TNSWidgets
./TNSWidgets.framework/TNSWidgets: replacing existing signature
~/work/_scratch/mydemo/platforms/ios

As you can see the .xcframework bundle isn't copied by Xcode into the .app/Frameworks directory but only the relevant platform's .framework. Maybe its something that Apple have changed in the latest Xcode version...

I've verified that the plugin version is correct and contains the .XCFramework in ./node_modules/@nota/nativescript-webview-ext/platforms/ios/NotaWebViewExt.xcframework

mbektchiev avatar Jan 16 '20 10:01 mbektchiev

I think this is really important issue and should be opened. I have to manually embed and sign this .xcframeworks now

PixsaOJ avatar Mar 14 '24 01:03 PixsaOJ

@PixsaOJ Please open an issue in https://github.com/NativeScript/ios with as much detail as possible if you are having issues in the latest iOS runtime.

rigor789 avatar Mar 14 '24 10:03 rigor789

@PixsaOJ Please open an issue in https://github.com/NativeScript/ios with as much detail as possible if you are having issues in the latest iOS runtime.

Readme basically says I have to do things manually. I've spent countless hours on this. Maybe i will create issue in the future but for now I'm just going to focus on developing apps. I did not have luck in Discord servers when I asked around about this issue.

I am also bit confused on which place is right to open issue. I am not trying to develop runtime, I just want to use it to copy my App_Resources/IOS/*.xcframework to proper folder and Embed & Sing for physical device. If I have to do this manually, then its okay but bit annoying.

PixsaOJ avatar Mar 14 '24 18:03 PixsaOJ

@PixsaOJ try this:

  1. create a folder, call it something for example test-plugin
  2. create a platforms/ios folder
  3. place your xcframeworks in this folder
  4. create a package.json with something like this:
{
  "name": "test-plugin",
  "version": "1.0.0",
  "private": true,
  "nativescript": {
    "platforms": {
      "ios": "*"
    }
  }
}

Then npm i --save ./test-plugin in your project. All the frameworks will be picked up and embedded into your app.

image image

rigor789 avatar Mar 14 '24 19:03 rigor789

@rigor789 Actually thank you so much!

I don't know why cant we do this without plugins. I'll consider sponsoring ❤️

PixsaOJ avatar Mar 14 '24 20:03 PixsaOJ