Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Class X is implemented in both" when executing unit tests in a project that use Cocoapods

I added a unit test target to an existing project that use Cocoapods.

When I started the tests it runs the iOS simulator and I had a bunch of warning on the Xcode's console:

Class PodsDummy_Pods is implemented in both /Users/me/Library/Developer/CoreSimulator/Devices/604372F1-E934-445C-B8F6-3D8C86AA8E41/data/Containers/Bundle/Application/2A1BCAE6-5127-4288-B0E7-15588A1C09D1/MyAPP..app/MyApp. and /Users/me/Library/Developer/Xcode/DerivedData/MyApp-fzjqljiyaapspvaylhszcbkhtijd/Build/Products/Debug-iphonesimulator/MyAppTests.xctest/MyAppTests. One of the two will be used. Which one is undefined.

This error message appears for each class contained in the pod used by my project.

At the end the project throws an EXC_BAD_ACCESS

When I typed bt in the Xcode's console, there is like an infinite loop on this error:

frame #130498: 0x000000012626e897 MyAppTests`___lldb_unnamed_function42$$MyAppTests + 135

Any suggestion?

like image 917
Jean Lebrument Avatar asked Oct 20 '15 09:10

Jean Lebrument


1 Answers

Finally found the solution to this problem ! On my side, I had this issue with my swift framework unit tests. My Podfile was looking like that :

def import_gtm
  send :pod, 'GoogleTagManager', '~> 5.0.8'
end

target 'MyFramework' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyFramework
  import_gtm
end

target 'MyFrameworkTests' do
  use_frameworks!

  # Pods for testing
end

Eventhough my tests were executing correctly, I had tons of logs, just like OP. After reading on this Github issue, I changed my Podfile for the following :

def import_gtm
  send :pod, 'GoogleTagManager', '~> 5.0.8'
end

target 'MyFramework' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyFramework
  import_gtm

  target 'MyFrameworkTests' do
    inherit! :search_paths
  end
end

I'm finally rid of all these warning logs ! Try to clean before rebuilding (cmd + alt + shift + K) or delete the DerivedData folder content :

rm -rf ~/Library/Developer/Xcode/DerivedData/*

I hope this helps !

like image 53
n3wbie Avatar answered Nov 15 '22 05:11

n3wbie