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.
Related
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.
I have a react-native app with bridged Swift code that is building, running, and archiving without issue with Xcode 10.0 with the default Release and Debug build configurations. I use Xcode -> Product -> Archive or the "Play" button and everything works as expected. Great!
Then today I added a new build configuration that is an exact duplicate of Release. It is named Release copy. I did the same for Debug as well, and its duplicate is Debug copy.
If I try to run the same Archive or Run tasks using the copies, the tasks fail at Precompile bridging header.
/Users/whaley/dev/app/theApp/theApp-Bridging-Header.h:5:9: error: 'React/RCTBridgeModule.h' file not found
#import <React/RCTBridgeModule.h>
^
1 error generated.
<unknown>:0: error: failed to emit precompiled header '/Users/whaley/Library/Developer/Xcode/DerivedData/theApp-ckvpglaqydwzhadbbyqoprcjvnod/Build/Intermediates.noindex/ArchiveIntermediates/theApp/PrecompiledHeaders/theApp-Bridging-Header-swift_320079J7441HX-clang_QK5YQQC41WXA.pch' for bridging header '/Users/whaley/dev/theApp/ios/theApp-Bridging-Header.h'
Odd, in my opinion, since this should be an exact copy of a build configuration that was working fine.
If I switch back to the original Build Configurations everything is fine. The originals consistently work and the copies consistently fail.
I tried disabling the Precompile bridging header task, but just encountered a different, and similar error. Again, the original build configs worked where the copies failed.
I'm already using Find implicit dependencies, the bridging header is named properly, I'm not using Cocoapods, I've rebooted and cleared Xcode's Derived Data, and please bear in mind that it does work fine normally. It's only these duplicate build configurations that fail.
Why might this be happening? Am I missing a step here? Is this perhaps a limitation of react-native and it only supports the default build configs?
Naturally, the moment I posted my question I managed to find the answer I needed via Google
Thanks to Mateusz Klimczak for clearly illustrating the problem and resolution on their website.
Add an entry to Headers Search Paths for each new Release build configuration:
$(BUILD_DIR)/Release-$(PLATFORM_NAME)/include
Add an entry to Library Search Paths for each new Release build configuration:
$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)
One might wonder why this is needed when we only change build configuration name and it was already working for Release. React Native supports Debug and Release build configurations out of the box, while any other configuration needs to be set up manually.
Sure enough, that fixed it. The answer is that only Release and Debug are supported out of the box, so that additional config is required for non-standard Build Configurations.
An attempt to print object (po command) in xcode 6 beta 6 OSX Swift project results in this error message:
(lldb) po managedObject
error: Error in auto-import:
failed to get module '__ObjC' from AST context
In this case the object in question is an instance of NSManagedObject.
Any advice on how to help auto-import in getting __ObjC module into LLVM Abstract Syntax Tree context?
As of Xcode 6.1 if you attempt the po command twice it will work on the second attempt. The first po command will always fail for each new debugging session but subsequent calls work.
Have same issue in xcode 7.3.1:
error: Error in auto-import:
failed to get module 'Touch' from AST context:
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml/tree.h"
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml/tree.h:17:10: error: 'libxml/xmlversion.h' file not found
#include <libxml/xmlversion.h>
^
could not build Objective-C module 'LibXML2'
But you can use fr v managedObject instead of po managedObject.
I'd recommend double-checking that you have the
-D DEBUG
flag set under 'Other Swift Flags' for the scheme that you're using to debug. I experienced similar issues when I'd accidentally deleted it.
A clean of my project and deleting DerivedData worked for me.
I discussed a similar error message with an Apple engineer at WWDC2017. It seems like this issue can have many causes, and I am aware that mine is slightly different than the one described above.
My team spent weeks trying to figure this out, and it ended up being a bug on Apple's compiler, which we could never have figured out by ourselves. Also, it has a VERY easy workaround.
So, this is just me posting the fix here, in order to maximize the probability that someone else does a search for this confusing error message, and finds this answer.
So, here it is. In our case, we had an Objective-C project using a mix of Swift and Objective-C frameworks. This fix might apply in slightly different contexts, just try it.
There happens to be a bug with the way the compiling flags get aggregated from the frameworks and the project, and the "pure Objective-C" project "activates" it.
Solution: add one single, empty Swift file ("Whatever.swift", or whatever) in your Objective-C project, making it not-pure-objective-c any more (new->file->Swift file, don't create the bridging header. The file will only contain the import of Foundation).
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.
I just installed XCode 4 today (using Apple mac app store), and I created a new Mac OS application, and tried to switch to test mode,and build the test skeleton code it generated for me. It failed here:
In mytests.h:
#import <SenTestingKit/SenTestingKit.h>
The error is:
file://..mytests.h: error: Lexical or Preprocessor Issue: 'SenTestingKit/SenTestingKit.h' file not found
Now, when I use locate from the terminal to find SenTestingKit.h, I notice it exists under the /Developer-old/Library/Frameworks folder (which is what XCode 4 installer renamed my /Developer folder to). There is no new /Developer/Library/Frameworks. And I can't seem to find SenTestingKit.framework on my disk, other than the developer-old one.
What's up? It seems SenTestingKit.framework is not shipped with XCode 4.
Update:
Furthermore, When I copy my old SenTestingKit framework from XCode 3 into /Developer/Library/Frameworks, it sort of builds, but it doesn't work the way I would expect. The dummy test is designed to just fail, but when I "run test", I just get the normal cocoa app document window opening, and no indication that my test has failed (as I intend it to do).
This is pretty bad. I can't get a Unit test to FAIL. That's not the usual situation for me, you understand.
You may find that the reason for this is because you've installed Xcode 4 into a directory such as /Xcode 4.x/ or similar. The space is causing the problem because the -I paths are "Xcode" and "4.x/Library/Frameworks".
To fix this, what you need to do is select your test target, and under its build settings go and find the Framework Search Path, and put quotes around the two arguments, so you have:
"$(SDKROOT)/Developer/Library/Frameworks" and "$(DEVELOPER_LIBRARY_DIR)/Frameworks"
Then you default tests will compile, link and fail.
You will maybe need to import the framework into your project. Otherwise, the header file won't be recognize.
If you can't see the framework you're looking for, you can adjust the framework look paths in your project's build settings.
When you're building unit tests in the same project as you main code, make sure that XCode 4 didn't automatically connect you mytests.m file into the "Compile Sources" section of your main code.
For example, if you have two targets in our project:
MyProject
MyProjectTests
Check the Build Phases for MyProject to see if XCode added mytests.m into the "Compile Sources" accordion. This will cause your builds to fail because SenTest isn't included in the main project.