which carthage: /usr/local/bin/carthagecarthage version: 0.30.1 xcodebuild -version: Xcode 9.4.1 (Build version 9F2000)--no-build? No--no-use-binaries? No--use-submodules? No--cache-builds? No--new-resolver? NoCartfile
binary "opencv2.json"
opencv2.json
{
"3.4.3": "https://github.com/opencv/opencv/releases/download/3.4.3/opencv-3.4.3-ios-framework.zip"
}
Command ran
carthage update
Carthage Output
*** Downloading binary-only framework opencv2 at "file:///Users/arturgrigor/Downloads/test/opencv2.json"
*** Downloading binary-only framework opencv2 at "file:///Users/arturgrigor/Downloads/test/opencv2.json"
*** xcodebuild output can be found in /var/folders/4l/1fk2vc_13m1b4bf4bwcjc3z80000gn/T/carthage-xcodebuild.eBZDi3.log
Failed to read file or folder at /Users/arturgrigor/Downloads/test/Carthage/Build/iOS/opencv2.framework
Actual outcome
Carthage did not finish successfully.
Expected outcome
Carthage should just download the framework and finish. I don't see why extra steps are needed in this case as long as the project builds perfectly with the downloaded framework as-is.
This may be already addressed in #2542; we need to check that for what platform a framework is built (to copy into appropriate Carthage/Build/$platform subdirectory).
I think this might have something to do with a problem @jdhealy looked at. My memory fails me right now.
I examined that the Info.plist in that framework actually does not contain CFBundleExecutable key, so I believe this is already fixed on master (by #2542). Closing.
I manually added the CFBundleExecutable entry in the Info.plist but now the process is stuck elsewhere, in the Copy Frameworks Build Phase.
Stripping the framework seems to break something in the codesign.
Copy Frameworks build phase output
A shell task (/usr/bin/xcrun codesign --force --sign - --preserve-metadata=identifier,entitlements /Users/arturgrigor/Library/Developer/Xcode/DerivedData/SomeApp-drffgqdfqwopeicnuknmmqlifxzk/Build/Products/Debug-iphonesimulator/SomeApp.app/Frameworks/opencv2.framework) failed with exit code 1:
/Users/arturgrigor/Library/Developer/Xcode/DerivedData/SomeApp-drffgqdfqwopeicnuknmmqlifxzk/Build/Products/Debug-iphonesimulator/SomeApp.app/Frameworks/opencv2.framework: replacing existing signature
/Users/arturgrigor/Library/Developer/Xcode/DerivedData/SomeApp-drffgqdfqwopeicnuknmmqlifxzk/Build/Products/Debug-iphonesimulator/SomeApp.app/Frameworks/opencv2.framework: bundle format is ambiguous (could be app or framework)
But manually running the codesign command with the original framework from the Carthage/Builds folder seems to work just fine. This is the output of that:
/usr/bin/xcrun codesign --force --sign - --preserve-metadata=identifier,entitlements Carthage/Build/iOS/opencv2.framework
Carthage/Build/iOS/opencv2.framework: replacing existing signature
@arturgrigor please use master. brew install carthage HEAD
@blender The master version seems to fix the carthage update issue but is not helping with the carthage copy-frameworks command.
* Copy Frameworks build phase output*
A shell task (/usr/bin/xcrun codesign --force --sign - --preserve-metadata=identifier,entitlements /Users/arturgrigor/Library/Developer/Xcode/DerivedData/SomeApp-drffgqdfqwopeicnuknmmqlifxzk/Build/Products/Debug-iphonesimulator/SomeApp.app/Frameworks/opencv2.framework) failed with exit code 1:
/Users/arturgrigor/Library/Developer/Xcode/DerivedData/SomeApp-drffgqdfqwopeicnuknmmqlifxzk/Build/Products/Debug-iphonesimulator/SomeApp.app/Frameworks/opencv2.framework: unsealed contents present in the root directory of an embedded framework
Are you trying with the binary you have manually added the plist key to or with a new binary? Please use an untouched binary as downloaded from the url you have provided. The error usually indicates that you have a file that is not supposed to be in the framework bundle.
I am trying to repro but I can't even get it to link properly, so I'm just run codesign manually and I don't have any issues with the downloaded binary.
@blender I tried with the untouched version. But for easier debugging, I created this test project so you can take a look at it. https://www.dropbox.com/s/l2kxf2qz485jl8w/OpenCV%20Carthage%20Test.zip?dl=0
Just download the ZIP, run carthage update and then open the project in Xcode and do a build. You'll see that the build fails and the output should look like this
A shell task (/usr/bin/xcrun codesign --force --sign - --preserve-metadata=identifier,entitlements /Users/arturgrigor/Library/Developer/Xcode/DerivedData/OpenCV_Carthage_Test-djapmviaolqhvyhkmnqgwvqjikab/Build/Products/Debug-iphonesimulator/OpenCV\ Carthage\ Test.app/Frameworks/opencv2.framework) failed with exit code 1:
/Users/arturgrigor/Library/Developer/Xcode/DerivedData/OpenCV_Carthage_Test-djapmviaolqhvyhkmnqgwvqjikab/Build/Products/Debug-iphonesimulator/OpenCV Carthage Test.app/Frameworks/opencv2.framework: unsealed contents present in the root directory of an embedded framework
Command /bin/sh failed with exit code 1
The binary that is downloaded is __crafted by hand__ and contains not one, but __two__ .DS_Store in it.
This is the first problem.
The second problem I believe has to do with the bundle structure, but I'm still trying to figure out what is wrong.
Quick fix, don't include this framework in the carthage-copy frameworks list
I see. Ok, but if I don't include it in the copy frameworks build phase then the framework won't get copied to the "Frameworks" folder so it won't be available at runtime.
If you include it in Linked Libraries and Frameworks and Xcode will copy it
Linked Libraries and Frameworks
No, that is just for linking but not for copying frameworks. "Embedded Binaries" should be what you mean.
@ikesyo Right, but I just checked a project of mine and it worked without that. I am wondering why now :D
I think I know why. Because these frameworks are static.
So yeah, sorry for the stream of consciousness but I just realized that there is nothing to copy here by definition so you should not be using copy-frameworks
I spent like __a day__ debugging this when I should have immediately realized it was supposed to be statically linked.
๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ๐คฆโโ๏ธ
unsealed contents present in the root directory of an embedded framework
For that code signing error, https://developer.apple.com/library/archive/technotes/tn2206/_index.html#//apple_ref/doc/uid/DTS40007919-CH1-TNTAG201 is a great hint.
opencv2.framework's top level structure is:
$ tree ~/Downloads/opencv2.framework -L 1
/Users/ikesyo/Downloads/opencv2.framework
โโโ Headers -> Versions/Current/Headers
โโโ Resources -> Versions/Current/Resources
โโโ Versions
โโโ opencv2 -> Versions/Current/opencv2
The framework structure is invalid; the opencv2 symlink should be the source of the issue. Removing that link should fix the code signing issue. I'll recommend you to file an issue on the upstream https://github.com/opencv/opencv.~~
Other related infos:
Anyway https://github.com/Carthage/Carthage/issues/2567#issuecomment-420373580 will be the right way for static frameworks.
I think it might be appropriate to enhance copy-frameworks to detect Mach-O types and reject static frameworks printing a notice that it will skip the item.
@blender As far as I know that's only true for static libraries but in my case this is a dynamic framework and technically, it needs to be copied to the Frameworks folder. But... I modified that sample project that I linked earlier and actually used the opencv dependency in a view controller and it runs without issues, so no crash as I expected at app launch.
So it makes me wonder why is that? Is it possible because the framework is written in C++ and it doesn't need the Objective-C runtime? ๐ค
I will run more tests in different environments and I'll post here an update if the framework needs to be listed in the "Embedded Binaries" section or not.
but in my case this is a dynamic framework
I examined that the framework included in https://github.com/opencv/opencv/releases/download/3.4.3/opencv-3.4.3-ios-framework.zip is actually a static one.
$ objdump -macho -private-header -non-verbose opencv2
Archive : opencv2
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
0xfeedfacf 16777223 3 0x00 1 4 672 0x00002000
...
All filetypes are 1 and that is MH_OBJECT, so the framework is static (dynamic library will be 6/MH_DYLIB).
@arturgrigor it's just packaged as a framework, but it's a static library and Xcode knows it :)
@ikesyo Wow, that's right. I just analyzed the Mach-O header and it says that the file is a static library. That makes a lot of sense for why the app didn't crash at runtime given the fact that the dependency wasn't embedded.
Thanks guys for your time on this! ๐
@ikesyo just out of curiosity what is your process to check if it's a static lib?
Ok we're using the same command.
@blender Yes, the command used at https://github.com/Carthage/Carthage/issues/2567#issuecomment-420379968 comes from https://github.com/Carthage/Carthage/blob/9192623a0487dd88e855ca1df91cb11249b8b695/Source/CarthageKit/MachHeader.swift#L67-L75 ๐
Let's close this again.
Most helpful comment
@arturgrigor it's just packaged as a framework, but it's a static library and Xcode knows it :)