CocoaPods intermediate files build failure with xcodebuild

I'm trying to get xcodebuild working with a CocoaPods project and have run into an issue. I'm running:

xcodebuild -workspace 'MyWorkspace.xcworkspace' -scheme DefaultScheme -configuration Release CODE_SIGN_IDENTITY="Distribution Profile" PRODUCT_NAME="MyProduct"

I get the following errors:

The following build commands failed:
    Libtool /Users/myuser/repos/MyProjectDir/Build/Intermediates/Pods.build/Release-iphoneos/Pods.build/Objects-normal/armv7s/libsupport.a normal armv7s
    Libtool /Users/myuser/repos/MyProjectDir/Build/Intermediates/Pods.build/Release-iphoneos/Pods.build/Objects-normal/arm64/libsupport.a normal arm64
    Libtool /Users/myuser/repos/MyProjectDir/Build/Intermediates/Pods.build/Release-iphoneos/Pods.build/Objects-normal/armv7/libsupport.a normal armv7

The builds work fine in xcode. I've googled this to death and have yet to find a solution. Anyone have any ideas?

Edit: I also get two lines like the following for every pod.

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lPods-AFNetworking
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lPods-AFNetworking is not an object file (not allowed in a library)

Second Edit: It works perfectly if I leave out the PRODUCT_NAME argument. What's up with that?


I have the same problem and found the root cause about the problem.

Environment: Xcode 6.1 (6A1052c), OSX 10.10 (14A389) and using CocoaPods for CocoaLumberjack.

Problem

The cause is the PRODUCT_NAME property not only affects built *.app but also library *.a files for CocoaPods.

In my scenario, I need to build many *.app files with different product name and some little different in image resources and settings. Thus, I want to build different *.app files in a build script which I can trigger the process with just a click.

Here's what happens if we set PRODUCT_NAME in xcodebuild's options with *.xcworkspace in following command:

xcodebuild -workspace $PROJECT_NAME.xcworkspace 
           -scheme $PROJECT_NAME 
           -configuration Distribution 
           CONFIGURATION_BUILD_DIR=$PROJECT_SRC/build 
           PRODUCT_NAME=$NEW_PRODUCT_NAME build
  • xcodebuild builds $NEW_PRODUCT_NAME.app
  • xcodebuild builds *.a libray files of CocoaPods with name $NEW_PRODUCT_NAME.a , which should be libPods-CocoaLumberjack.a and libPods.a 在这里输入图像描述
  • In the linker step, project settings ask for linking with libraries by properties -lPods and -lPods-CocoaLumberjack (In your scenario, it failed in linking -lPods-AFNetworking ). Since library files are also affected by PRODUCT_NAME property, linker cannot find find *.a files. 在这里输入图像描述
  • Build fail
  • My solution

    Finally, my solution is that build the project and CocoaPods libraries separately .

  • In project's src folder
  • Build CocoaPods libraries with following command

    xcodebuild -project Pods/Pods.xcodeproj build
    
  • Build project with following command and add CocoaPods and other necessary libraries in search path ( Don't forget to include all your necessary libraries )

    xcodebuild -project $(TARGET_PROJ) 
               -configuration Distribution 
               -target $(TARGET_TAR) 
               PRODUCT_NAME=$(NEW_PRODUCT_NAME) 
               LIBRARY_SEARCH_PATHS="./Pods/build/Release-iphoneos $OTHER_PATH" 
    
  • Build!

  • These are worked for me to have a one-click build script for same binary but with some different images and settings. Hope this will help someone who have the same problem.


    Unfortunately xcodebuild is one the worst documented tools I've ever worked with. Possibly the mentioned character was the issue but never know :/ What I can add is that in general You should avoid passing arguments such as PRODUCT_NAME via command line. It's much better to create multiple configurations and just switch them while building artifacts. From my experience I know that these arguments cause strange behavior sometimes.


    Turns out, xcodebuild did not like the PRODUCT_NAME argument to be last. I deleted the argument altogether and everything built. Then I moved the PRODUCT_NAME to before CODE_SIGN_IDENTITY and it worked. So, I thought it might have built the second time because the pods resources were built and living in the derived data folder. To check that out, I blew away the derived data and built again (with the PRODUCT_NAME argument last) and it built just fine.

    Honestly, I'm not sure what the heck the problem was. Perhaps this will help someone out in the future. If anyone has a real solution, I would love to hear it.

    链接地址: http://www.djcxy.com/p/89638.html

    上一篇: 找不到Cocoapods <RestKit / RestKit.h>

    下一篇: CocoaPods中间文件使用xcodebuild构建失败