XCTest fails after adding CloudKit capability - xcode

After I enabled CloudKit my tests fail to run, apparently because the test bundle cannot be code signed correctly:
The bundle “XXXTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2020-01-06 09:11:40.551130+0100 XXX[2581:20975 (dlopen_preflight(/Users/xxx/Library/Developer/Xcode/DerivedData/XXX-gznytogyqukfvnawlueveokdvdrw/Build/Products/Debug/XXX.app/Contents/PlugIns/XXXTests.xctest/Contents/MacOS/XXXTests): no suitable image found. Did find:
/Users/xxx/Library/Developer/Xcode/DerivedData/XXX-gznytogyqukfvnawlueveokdvdrw/Build/Products/Debug/XXX.app/Contents/PlugIns/XXXTests.xctest/Contents/MacOS/XXXTests: code signature invalid for '/Users/xxx/Library/Developer/Xcode/DerivedData/XXX-gznytogyqukfvnawlueveokdvdrw/Build/Products/Debug/XXX.app/Contents/PlugIns/XXXTests.xctest/Contents/MacOS/XXXTests')
I already tried cleaning the build folder, remove the derived data folder, manually download profiles, searched the web for similar issues and tried proposed solutions, even restarted my Mac and reintegrated CocoaPods although I think this is completely unrelated.
What am I missing?

Solved it by giving the test target its own entitlements file that does not have any CloudKit references. Also for the test target I used NSPersistentContainer instead of NSPersistentCloudKitContainer. In other words: the application target is using CloudKit but the test target is not. This allowed the tests to succeed again while the application itself is enabled to synchronise via iCloud.

Related

How to solve "Bad CFBundleExecutable" validation error with app store and CocoaPods framework

I'm having several tricky problems with getting my Mac app with CocoaPods to pass validation into the Mac App Store. It works fine running locally but when I validate, it fails with these errors:
App Store Connect Operation Error
Bad Bundle Executable. You must include a valid CFBundleExecutable key in the nested bundle Pods_MSVAPI_macOS [...<stuff>…Contents/Frameworks/MSVAPI.framework/Versions/A/Frameworks/Pods_MSVAPI_macOS.framework] property list file.
App Store Connect Operation Error
Bad CFBundleExecutable. Cannot find executable file that matches the value of CFBundleExecutable in the nested bundle Pods_MSVAPI_macOS [...<stuff>…Contents/Frameworks/MSVAPI.framework/Versions/A/Frameworks/Pods_MSVAPI_macOS.framework] property list file.
(MSVAPI.framework is my own framework that my app uses, which I intend to be cross-platform)
I read this https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleexecutable and it says "For a framework, it's the shared library framework and must have the same name as the framework but without the .framework extension.". So I tried putting "Pods_MSVAPI_macOS" which is the framework name without the .framework in the "Executable" info entry. No luck.
My next attempt to fix this was to remove the target of Pods_MSVAPI_macos because that's not the actual framework - I have two CocoaPods that I'm using, each which creates its own framework bundle. That worked for getting through validation. But when I came to distribute the app, which I tried locally, it crashed with a "resource not found":
Dyld Error Message:
Library not loaded: #rpath/<podname>.framework/Versions/A/<podname>
Referenced from: /Applications/<appname>.app/Contents/Frameworks/MSVAPI.framework/Versions/A/MSVAPI
Reason: image not found
If I try to add the frameworks directly they are greyed out so it appears that they aren't actually being built independently:
How can I make sure that this CocoaPod's framework (and presumably the other one) gets included in the app bundle, and allow MSVAPI.framework to use it?
Alternatively, how can I get past the CFBundleExecutable validation error at the beginning of my question?
Thanks!

iTunes Connect - Invalid Bundle -> Bitcode Issue

I have a problem with my build becoming invalid in iTunes Connect. I have a workspace consisting of app project, library project and cocoa pods project in it. My cocoa pods has only KeychainSwift and GoogleMaps in it.
From iTunes Connect I get the reason described as
Invalid Bundle - This app includes files that were built with bitcode enabled but without doing an Archive or Install build, possibly from a library or framework that was imported but not built as part of the project. Full bitcode content is only generated in an Archive or Install build.
I have bit code enabled in settings and also do Product->Archive but it somehow does not work. Am I doing something wrong is it because of the libraries? Is there a way to find out which one is the problem?
After a couple of different things I tried one seems to be the solution for my problem: The location of my own library copied to the app project needs to be Location: "Relative to Group" (not "Absolute Path"). Now it was accepted by iTunes Connect.

Cannot run tests after adding a Swift file

I have a project that is several years old, and I now want create a new feature in Swift. However, I cannot get the unit tests to run after I have inserted the first swift file. The tests compile, and the simulator is started. But before the tests start to run, I get this error:
Simulator session started with process 58478
Debugger attached to process 58478
IDEBundleInjection.c: Error 3587 loading bundle '/Users/jrv/Library/Caches/AppCode32/DerivedData/MobileBank-542f20a4/Build/Products/Debug-iphonesimulator/Test.xctest': The bundle “Test.xctest” couldn’t be loaded because it is damaged or missing necessary resources.
DevToolsBundleInjection environment:
XCInjectDiagnostics: (null)
XCInjectBundleInto: /Users/jrv/Library/Caches/AppCode32/DerivedData/MobileBank-542f20a4/Build/Products/Debug-iphonesimulator/Sydbank.app/Sydbank
XCInjectBundle: /Users/jrv/Library/Caches/AppCode32/DerivedData/MobileBank-542f20a4/Build/Products/Debug-iphonesimulator/Test.xctest
TestBundleLocation: (null)
TMPDIR: /Users/jrv/Library/Developer/CoreSimulator/Devices/8016383A-A404-4D35-BDCB-0ED5317AD44A/data/Containers/Data/Application/CA2E7792-CA10-4109-B95E-7B0CA9D18147/tmp
DYLD_LIBRARY_PATH: /Users/jrv/Library/Caches/AppCode32/DerivedData/MobileBank-542f20a4/Build/Products/Debug-iphonesimulator
DYLD_INSERT_LIBRARIES: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection
DYLD_FRAMEWORK_PATH: /Users/jrv/Library/Caches/AppCode32/DerivedData/MobileBank-542f20a4/Build/Products/Debug-iphonesimulator
DYLD_FALLBACK_LIBRARY_PATH: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib
DYLD_FALLBACK_FRAMEWORK_PATH: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks
Even the simplest swift file gives the same error:
import Foundation
class MyTests: XCTestCase {
}
Searching Stack Overflow have given several suggestions. I have tried to remove code signing, I have ensured I am using XCTest, I have changed my framework search paths, I have Symbols hidden by Default = NO, and I have ensured that my bridging headers are correctly configured.
Any suggestions will be greatly appreciated...
I tried creating a new test target for my Swift files, and this target worked. Then I compared the configuration, parameter by parameter, between my old test target and the new one. I finally identified one parameter that caused the tests to run when I set it on my test target:
Full setting:
LD_RUNPATH_SEARCH_PATHS = "$(inherited) #executable_path/Frameworks #loader_path/Frameworks"
To be honest, I don't know what this means, but it works.

iOS error "Embedded binary is not signed with the same certificate as the parent app"

Those are my first steps in IOS applications development and I'm facing some problem that I can't figure out.
error: Embedded binary is not signed with the same certificate as the parent app. Verify the embedded binary target's code sign settings match the parent app's.
Embedded Binary Signing Certificate: Not Code Signed
Parent App Signing Certificate: iPhone Developer: Emil Adz (9QNEF95395)
I can't understand, what is a Embedded Binary Signing Certificate?
I went over the questions with the same error here, but none of them were related to the problem presented here (Not Code Signed).
I tried to revoke my certificate from the Apple Developer Member Center and request another certificate, but the issue persists.
Does some know how it could be fixed?
Swift 5 . Simple way in my case check this screen shot i am done
The embedded binary is referring to a widget that you are deploying alongside with your app.
In your case, you are not signing your widget with any Signing Identity (since your error says "Not Code Signed").
To resolve this, go to your Project file, find your widget's target, and under the Build Setting tab, find the Code Signing Identity value. Choose the same code signing identity that you are using for your main app's target.
You will also need to create and configure a provisioning profile specifically for your widget when you want to release it.
Sometimes none of the solution on Stackoverflow works. In that case,
Solution
Make sure that there is no red mark/issue in any of the sections of Signing(Debug), Signing(Release) and Enabled capabilities in both of MainApp and EmbeddedApp
Make sure that both certificates and provisioning profiles are installed under login/system keychain.
Make sure that your certificate is never ever set as Always Trust. Access must be kept as Use System Default
This error is also shown when deployment target of your Today extension is newer than the parent app. They must be the same.
I have iOS app set to 10.0 and added Today extension which was automatically set to 11.4 as the latest. This caused the error to appear. Simply changing the Deployment target of the extension target to 10.0 resolved the issue.
Assumptions
the app I am working is called TestApp (for the sake of privacy)
the steps below are tested in Xcode 11.1
the scheme I was using to compile is AdHoc
the app has the Push Notification capability
Issue
In my case the issue was caused by a discrepancy between the signing of two targets. The issue was between:
the TestApp target (i.e. what in the error is referred to as Parent App Signing Certificate)
the notificationServiceExtension target (i.e. what in the error is referred to as Embedded Binary Signing Certificate).
Resolution
In my AdHoc scheme, under the TestApp target, I disabled the automatic signing because I wanted to specify the provisioning profile and the certificate.
The steps I followed were:
from Signing & Capabilities -> AdHoc -> Signing (section)
removed the tick from Automatically manage signing under selected
selected the provisioning profile I wanted to use
from Build Settings -> Signing (section)
under Code Signing Identity, choose for both AdHoc and Any SDK the certificate I wanted to use
under Code Signing Style -> AdHoc, chose Manual
under Provisioning Profile -> AdHoc, chose the provisioning profile I wanted to use (i.e. the same as step 1.2)
The error was thrown because I didn't apply the same settings to the notificationServiceExtension target (which was still using the automatic signing and therefore another certificate). As soon as I have repeated the steps above also for this target, the error was gone.
I hope it can helps someone, because this error drove me crazy!
It seems this issues appears in xcode 10 and the resolution is different from the aforementioned.
I was able to fix (or rather bypass) the error by setting the Build
System to Legacy (via File > Workspace Settings)
Another interesting thing to note is that the signing error would not
occurr if I was building to an actual device (i.e. before changing the
Build System to Legacy). It would only occurr when building using the
simulator and only on Xcode 10 beta 3, 4 and 5.
Link to the original thread: https://forums.developer.apple.com/thread/105537
I was having this issue when I migrated to Xcode 10 and managed to fix it by updating the architectures in "Build Settings"> "Valid Architectures" for the Watch target to
$(ARCHS_STANDARD)
This thread helped me out a lot: https://forums.developer.apple.com/thread/107563
Oddly enough, I had to remove the products folder from my project in order to fix this error. Xcode crashed then, after reopening, worked like a charm!
I got this error when the App Groups weren't set up correctly on all my App IDs in the Developer Portal. Therefor the App Groups in the app didn't work correctly and the Binary for the extension or the Watchkit app couldn't be signed.
check your Excluded Architectures
I got this error after adding a Copy Files Build Phase to the main app Target.
Copy Files
Destination: Absolute Path
Path: /Applications
File: MyApp.app
This worked the first time I ran the app.
On subsequent runs, Xcode began complaining about the certificate mismatch.
Removing the Copy Files build phase fixes the certificate mismatch. I'm still searching for a way to Copy Files without the error.
Same issue links:
https://stackoverflow.com/a/32802258/1265393
https://forums.developer.apple.com/thread/102707
https://github.com/Bouke/SwiftInitializerGenerator/issues/6
I had the issue when following the SwiftUI documentation about integrating an iOS app with watchOS.
The issue is that the extension is not under the same development team, so it will fail when we try to compile it.
Nothing about architecture and nothing about trust.
SOLUTION:
ScreenShot for xcode
Go to the project general file
Check on the extension folder on the sidebar (check the screenshot number 2)
Switch to the Signing & Capabilities tab
Choose your team (need to match the master project's development team)
I had this problem with a Photo Editing Extension. I eventually discovered that it was due to my unusual project structure.
My project includes a local Swift package containing all the source code and resources for the appex (app extension).
The appex links the library created by the Swift package.
The appex has no source files of its own. The “Compile Sources” build phase has no files, and it has no “Copy Bundle Resources” build phase.
On a clean build, Xcode builds the appex and embeds it in the app successfully.
On an incremental build, even with no changes to any file, Xcode fails during the “Validate MyEx.appex” step.
The problem, it turns out, is that Xcode re-links the appex executable every time it builds, even if nothing has changed. And Xcode does not then sign the new appex executable, except during a clean build.
This means that the appex executable is always unsigned after an incremental build, so it is never signed with the same certificate as the parent app (because the appex isn't signed at all).
My solution was to add an empty file, dummy.swift, to the appex target. That is sufficient to make Xcode only re-link the appex when needed, and to always sign the appex after linking during an incremental build.
I got this error while having another compile time error in my code.
My new target has never been built before.
So I thought I'll fix this error first. But it turned out, that fixing the other error enabled Xcode to build the target and fix the other error itself.
Check if you have more targets like oneSignal or other else and check if you have the same team of the main target.
I was getting this error trying to build a WatchOS app in Xcode 11 - I tried all the various suggestions in this and other SO posts but the thing that finally worked was switching Xcode to use the legacy build system.
Go to: File | Project (or Workspace) Settings | Build System
And select Legacy Build System
XCode 12.5
In my case, I followed Shakeel Ahmed's answer. But I also needed to do this change on the Pod file.
You can find more here https://github.com/facebook/react-native/issues/31480#issue-876308920
I have experienced this same issue in a Unity.iPhone project.
We embed a target for a Stickers extension that we ship with the app.
The Stickers extension target is the one complaining about the code sign settings not matching the parent apps.
error: Embedded binary is not signed with the same certificate as the parent app. Verify the embedded binary target's code sign settings match the parent app's.
Embedded Binary Signing Certificate: Software Signing
Parent App Signing Certificate: Apple Distribution
This occurred when the Stickers Extension target build settings were set to ARCHS_STANDARD (arm7, arm64), while the parent app was set to arm64.
I fixed this by setting the Extension's ARCHS build property to arm64.
Go figure, I suspect this output catches a bunch of different issues and just doesn't specify any details in the log message.
Check your keychain access expire certificate not deleted that's why its showing a error.
In my case the key was to delete 'Products' folder. Then the build was successful. Moreover, after that I made git reset --hard and tried again with the same successful result.

Swift build fails: target might include it's own product

Has anyone run into this issue? I was experimenting with porting an existing obj-c app to Swift, and after quite a few successful builds the project will no longer build and immediately gives the error: Unable to run command 'CompileSwift normal' - this target might include its own product. Along with many other 'target might include it's own product errors'.
What I've Tried:
Checking Target Dependencies: There is nothing listed as a target dependency in Build Phases.
I've tried completely deleting the product folders, and have went through all the files multiple times but with no luck.
If I simply replace the Swift files with the old obj-c files it builds fine, no errors at all.
Restoring to a snapshot prior to any Swift modifications results in building as normal, but even if I add a brand new Swift boilerplate file and bridging header, then click build, it fails with the same errors.
I had the same issue. I couldn't work out exactly what was causing it, but realised the same code would build find on a different Xcode 6 install on a different machine.
I solved it by deleting my cached builds, etc, in ~/Library/Developer/Xcode, while Xcode is not running. "Clean" alone from within Xcode didn't do it.
You should find that when you re-launch Xcode your app will build fine.
Deleting my app target from "Build Phases -> Copy Bundle Resources" worked for me. (Somehow it was being included for bundling?)
I could reproduce the problem. In the objc-to-swift bridge header I imported a header of an objc class, which also imports swift-to-objc header. There was a cycle of imports and this could be the reason Xcode complaint.
I think for now it is best to avoid such cyclic importing between swift and objc. You might want to check that out.

Resources