Libraries not found when using CocoaPods with iOS logic tests

前端 未结 14 1291
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 15:41

I am trying to write some iOS logic tests against classes in my project that use functionality from some of the libraries in my podspec. I am using the standard unit test bu

相关标签:
14条回答
  • 2020-11-29 16:17

    I had issues using OpenCV under XCTest. It was giving me linker errors of Undefined symbols for architecture arm64 for classes like cv::Mat. I am installing OpenCV through CocoaPods using pod 'OpenCV', '~> 2.0' under the main target. No matter how hard I tried to put the OpenCV dependency under the test target or use inherit! :search_paths none of it worked. The solution was to create an abstract_target like so:

    # Uncomment the next line to define a global platform for your project
    platform :ios, '6.1.6'
    
    abstract_target 'Shows' do
      pod 'RMVision', path: '../..'
      pod 'RMShared', path: '../../../RMShared'
      pod 'OpenCV', '~> 2.0'
    
      target 'RMVisionSample' do
        # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
        # use_frameworks!
    
        # Pods for RMVisionSample
      end
    
      target 'RMVisionSampleTests' do
        # inherit! :search_paths
        # Pods for testing
      end
    
      target 'RMVisionBenchmarks' do
        # inherit! :search_paths
        # Pods for testing
      end
    
    end 
    
    

    Also useful are the pod deintegrate & pod clean commands which help to cleanup the project and make sure that you start fresh when testing. You can install those two using [sudo] gem install cocoapods-deintegrate cocoapods-clean.

    0 讨论(0)
  • 2020-11-29 16:21

    CocoaPods 1.0 has changed the syntax for this. It now looks like this:

    def shared_pods
        pod 'SSKeychain', '~> 0.1.4'
        ...
    end
    
    target 'Sail' do
        shared_pods
    end
    
    target 'Sail-iOS' do
        shared_pods
    end
    

    Pre CocoaPods 1.0 answer

    What you want to use is link_with from your Podfile. Something like:

    link_with 'MainTarget', 'MainTargetTests'
    

    Then run pod install again.

    0 讨论(0)
  • 2020-11-29 16:24

    You can use link_with according to @Keith Smiley solution.

    In case you have common pods, and specifics for each target, you might want to use the "def" option to define group of pods. and use the "def" later in exclusive target.

    def import_pods
        pod 'SSKeychain'
    end
    
    target 'MyProjectTests', :exclusive => true do
      import_pods
    end
    
    target 'MyProject', :exclusive => true do
      import_pods
      pod 'Typhoon'
    end
    

    in the example above, I added 'SSKeychain' to the both targets, and 'Typhoon' only to 'MyProject' target

    0 讨论(0)
  • 2020-11-29 16:24

    Try This it's working for me ,

    We need to set Pods in Configurations ,

    The Project->Info->Configurations in the Xcode project (your project) should be set to main project 'Pods' for Debug, Release (and what else you have). See "Headers not found – search paths not included"

    Hope this is help to some one .

    0 讨论(0)
  • 2020-11-29 16:25

    I had a similar occurrence when I lost some library files during some version control. I still saw the library file in my Pods but with the actual code missing, XCode said it was gone. To my dismay, running 'pod install' wasn't immediately bringing the lost files back.

    I had to remove and replace the pod manually by doing the following:

    1. Remove the library from the Podfile
    2. Run 'pod install' to remove the library completely
    3. Put the library back into the Podfile
    4. Run 'pod install' again

    This should put the library in question back in it's original form.

    0 讨论(0)
  • 2020-11-29 16:25

    It's also worth noting that if you have libPods.a added twice, you'll get some nasty error like this:

    232 duplicate symbols for architecture i386
    

    To fix it, just delete one of the libPods.a references in your Project Explorer.

    0 讨论(0)
提交回复
热议问题