10

I'm developing a cocoa touch framework and I'm importing "RealmSwift" using CocoaPods. The project builds successfully but the tests fails to load. I'm getting the following error:

xctest (97035) encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying error: The test runner failed to load the test bundle. Executable cannot be loaded for some other reason, such as a problem with a library it depends on or a code signature/entitlements mismatch.))

Crash log:

2019-02-27 17:35:44.197599+0400 xctest[12408:121075] The bundle “MyFrameworkTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2019-02-27 17:35:44.197835+0400 xctest[12408:121075] (dlopen_preflight(/Users/zakaria/Library/Developer/Xcode/DerivedData/MyFramework-cltpexonmtkefveximwygxbkkcrj/Build/Products/Debug-iphonesimulator/MyFrameworkTests.xctest/MyFrameworkTests): Library not loaded: @rpath/Realm.framework/Realm
  Referenced from: /Users/zakaria/Library/Developer/Xcode/DerivedData/MyFramework-cltpexonmtkefveximwygxbkkcrj/Build/Products/Debug-iphonesimulator/MyFrameworkTests.xctest/MyFrameworkTests
  Reason: image not found)

I tried every solution I could find online, but to no avail.

It's worth mentioning that this works successfully in a iOS project, the problem occurs only in a cocoa touch framework.

My podfile is as follow:

target 'Framework' do
  use_frameworks!

  pod 'RealmSwift', '~> 3.13.1'

  target 'FrameworkTests' do
    inherit! :search_paths
  end

end

I'm using Xcode version: 10.1 and CocoaPods version: 1.6.0

Zakaria
  • 1,040
  • 3
  • 13
  • 28

5 Answers5

7

Go to your test logs in Derived data folder:

~/Library/Developer/Xcode/DerivedData/APP_BUILD_FOLDER/Logs/Test

You will find a .xcresult test result bundle, right-click it and choose Show package contents and in 1_Test/Diagnostics folder, you should find run/crash log for your tests.

This log will give you an exact cause of your fail, you can post it here if you don't know what to do with it after you find it, we will help you :-)

Without this log, cause of your issue could be literally anything, since this is rather generic xcbuild fail message.

Václav
  • 990
  • 1
  • 12
  • 28
6

This is the podfile that worked for me:

platform :ios, '11.0'

def shared
  use_frameworks!
  pod 'RealmSwift', '~> 3.18.0'
end

target 'Framework' do
  shared
end

target 'FrameworkTests' do
  shared
end
Zakaria
  • 1,040
  • 3
  • 13
  • 28
1

Oky, thx for logs this should fix your issue:

target 'Framework' do
  use_frameworks!

  pod 'RealmSwift', '~> 3.13.1'

  target 'FrameworkTests' do
    inherit! :search_paths
    pod 'RealmSwift', '~> 3.13.1'
  end

end

You don't have the RealmSwift library installed for your test target in pods, only for your app, as you can tell from log:

...Library not loaded: @rpath/Realm.framework/Realm referenced from...MyFrameworkTests.xctest...

Add code above to your podfile and run pod update :-)

Václav
  • 990
  • 1
  • 12
  • 28
  • I already tried that, but it didn't work. Please check my question again for an example where you can reproduce the problem. – Zakaria Feb 28 '19 at 12:09
  • Why are you doing `inherit! :search_paths`? That should not be needed in this case. Try to remove it and `pod update`. – Václav Feb 28 '19 at 16:16
0

Similar modification helped me.

use_frameworks!

target 'Framework' do

  pod 'RealmSwift', '~> 3.13.1'

end

target 'FrameworkTests' do

  pod 'RealmSwift', '~> 3.13.1'

end

Feel free to use "def" link

Nuzhdin Vladimir
  • 1,714
  • 18
  • 36
0

I encountered this issue recently when attempting to run our UI Tests target after our min deployment target was updated from 11.0 to 13.2, which failed immediately on launch. Oddly enough, updating the target all the way up to 12.4 worked just fine, but anything >= 13.0 resulted in the error

The bundle "MyAppUITests" couldn't be loaded. Try reinstalling the bundle.

The single change that resolved it (beyond ensuring that deployment target was set consistently across all targets, and in the Podfile) was to clear out the value we had listed in the BUNDLE_LOADER Build Setting within our UI Test Target.

Before:

BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp";

After:

BUNDLE_LOADER = "";
Alex Koshy
  • 1,613
  • 15
  • 17