Cocoapods: pod install error :undefined method `path' for nil:NilClass

Created on 14 Jul 2016  Â·  12Comments  Â·  Source: CocoaPods/CocoaPods

ℹ Please fill out this template when filing an issue.
All lines beginning with an ℹ symbol instruct you with
what info we expect.
Please remove this line and all above before submitting.

Report

What did you do?

ℹ Please replace this with what you did.
Run pod install

What did you expect to happen?

ℹ Please replace this with what you expected to happen.
Install all pod dependencies correctly.

Correct installation

ℹ Please replace this with of what happened instead.
NoMethodError - undefined method `path' for nil:NilClass

ℹ Please replace this with the output of pod env.

NoMethodError - undefined method `path' for nil:NilClass
/Library/Ruby/Gems/2.0.0/gems/xcodeproj-1.1.0/lib/xcodeproj/project/object/native_target.rb:462:in `block in add_file_references'
/Library/Ruby/Gems/2.0.0/gems/xcodeproj-1.1.0/lib/xcodeproj/project/object/native_target.rb:461:in `map'
/Library/Ruby/Gems/2.0.0/gems/xcodeproj-1.1.0/lib/xcodeproj/project/object/native_target.rb:461:in `add_file_references'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer/target_installer/pod_target_installer.rb:100:in `block in add_files_to_build_phases'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer/target_installer/pod_target_installer.rb:76:in `each'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer/target_installer/pod_target_installer.rb:76:in `add_files_to_build_phases'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer/target_installer/pod_target_installer.rb:21:in `block in install!'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/user_interface.rb:141:in `message'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer/target_installer/pod_target_installer.rb:17:in `install!'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:621:in `block (2 levels) in install_libraries'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:619:in `each'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:619:in `block in install_libraries'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/user_interface.rb:141:in `message'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:618:in `install_libraries'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:170:in `block in generate_pods_project'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/user_interface.rb:63:in `section'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:167:in `generate_pods_project'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/installer.rb:119:in `install!'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/command/install.rb:37:in `run'
/Library/Ruby/Gems/2.0.0/gems/claide-1.0.0/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/lib/cocoapods/command.rb:50:in `run'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.0.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `<main>'

ℹ Please link to a project we can download that reproduces the issue.
You can delete this section if your issue is unrelated to build problems,
it's only an issue with CocoaPods the tool.

defect

Most helpful comment

sudo vim
/Library/Ruby/Gems/2.0.0/gems/xcodeproj-1.1.0/lib/xcodeproj/project/object/native_target.rb
search function add_file_references
add if file end wrap the function ;this fix my problem
here is the function modified:

    def add_file_references(file_references, compiler_flags = {})
      file_references.map do |file|
        if file #avoid nil
        extension = File.extname(file.path).downcase

        header_extensions = Constants::HEADER_FILES_EXTENSIONS
        is_header_phase = header_extensions.include?(extension)
        phase = is_header_phase ? headers_build_phase : source_build_phase

        unless build_file = phase.build_file(file)
          build_file = project.new(PBXBuildFile)
          build_file.file_ref = file
          phase.files << build_file
        end

        if compiler_flags && !compiler_flags.empty? && !is_header_phase
          (build_file.settings ||= {}).merge!('COMPILER_FLAGS' => compiler_flags) do |_, old, new|
            [old, new].compact.join(' ')
          end
        end

        yield build_file if block_given?

        build_file
      end#endif
 end 
    end

All 12 comments

As the issue template requests, please attach a project that we can use to debug the issue. Thanks!

sudo vim
/Library/Ruby/Gems/2.0.0/gems/xcodeproj-1.1.0/lib/xcodeproj/project/object/native_target.rb
search function add_file_references
add if file end wrap the function ;this fix my problem
here is the function modified:

    def add_file_references(file_references, compiler_flags = {})
      file_references.map do |file|
        if file #avoid nil
        extension = File.extname(file.path).downcase

        header_extensions = Constants::HEADER_FILES_EXTENSIONS
        is_header_phase = header_extensions.include?(extension)
        phase = is_header_phase ? headers_build_phase : source_build_phase

        unless build_file = phase.build_file(file)
          build_file = project.new(PBXBuildFile)
          build_file.file_ref = file
          phase.files << build_file
        end

        if compiler_flags && !compiler_flags.empty? && !is_header_phase
          (build_file.settings ||= {}).merge!('COMPILER_FLAGS' => compiler_flags) do |_, old, new|
            [old, new].compact.join(' ')
          end
        end

        yield build_file if block_given?

        build_file
      end#endif
 end 
    end

Thanks! it solved my problem!

Thanks! Also solved the problem for me. I received the error after adding a .xcassets directory to my framework and trying to execute pod install in my example project.

i have the same problem,but i can't resolve it..who can help me @liuqianios ,you can? very thanks

I had the same issue and the change suggested by @RayCyder fixed it, thanks!

What is the reason for this error? Why is the file var nil sometimes?

I'm sorry to say that but In my opinion this is a terrible hack. I mean you pretty much ignore the warning instead of fixing the underlying problem and you end up in an unpredictable state.

When i ran into this problem it was mostly caused by an invalid podspec in a pod that I used. Most often there is something like this:
s.source_files = '*/.{h,m}'

Given that you pod structure looks like
/MyPod.posdpec
/MyPod.xcodeproj
/MyPod/MyPod.h
/MyPod/MyPod.m

your podspec has to point to the subfolder with the code in it:
s.source_files = 'MyPod/*/.{h,m}'

@efalkenberg was on track for me. I had added a new Core Data model to my project and I hadn't accommodated it in the .podspec. Once I did that, I stopped having this problem. I didn't have to use the fix suggested by @RayCyder. In my .podspec, I used:

s.resources = "AppName/Assets/*.xcdatamodeld"

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Hi!
Just a side note if somebody stumbles upon this issue on the internet. I had also added a Core Data model to my project and had the same issue. I had the .xcdatamodeld where my source_files pointed. If I moved it outside the path referenced and added it as resources it fixed it.

On CocoaPods 1.4.0, this produces the following error message:

[!] Unable to find other source ref for /Users/eric/Projects/tmp/Fram_iOS_XMPPManager/Pod/Classes/XMPP/Extensions/XEP-0045/CoreDataStorage/XMPPRoom.xcdatamodeld/XMPPRoom.xcdatamodel/contents for target GTIXMPPManager-iOS7.0.

This seems appropriate, as .xcdatamodeld should be add to resources. I think this can be closed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dawnnnnn picture dawnnnnn  Â·  3Comments

hmistry picture hmistry  Â·  3Comments

marzapower picture marzapower  Â·  3Comments

intelliot picture intelliot  Â·  3Comments

spencerkohan picture spencerkohan  Â·  3Comments