【问题标题】:How to remove CocoaPods from a project?如何从项目中删除 CocoaPods?
【发布时间】:2013-05-01 21:37:35
【问题描述】:

从项目中删除 CocoaPods 的正确方法是什么?我想删除整个 CocoaPod。由于我的客户施加的一些限制,我无法使用它。我只需要一个 xcodeproj 而不是 xcworkspace。

【问题讨论】:

标签: xcode cocoapods


【解决方案1】:

从项目中删除 CocoaPods 是可能的,但目前 CLI 无法自动执行。首先,如果您遇到的唯一问题是无法使用xcworkspace,您可以使用带有xcodeprojs 的CocoaPods,方法是使用--no-integrate 标志,这将产生Pods.xcodeproj,但不是工作区。然后您可以将此xcodeproj 作为子项目添加到您的主xcodeproj。

如果你真的想删除所有 CocoaPods 集成,你需要做一些事情:

注意如果操作不当,编辑其中一些内容可能会破坏您的主项目。我强烈建议您将项目检查到源代码管理中以防万一。这些说明也适用于 CocoaPods 版本0.39.0,它们可能会随着新版本的变化而变化。

  1. 删除独立文件(Podfile Podfile.lock 和您的 Pods 目录)
  2. 删除生成的xcworkspace
  3. 打开您的xcodeproj 文件,删除对Pods.xcconfig 和libPods.a 的引用(在Frameworks 组中)
  4. 在Build Phases 下删除Copy Pods Resources、Embed Pods Frameworks 和Check Pods Manifest.lock 阶段。
  5. 这似乎很明显,但您需要以其他方式集成第 3 方库或从代码中删除对它们的引用。

在这些步骤之后,您应该使用在集成 CocoaPods 之前存在的单个 xcodeproj 进行设置。如果我遗漏了任何内容,请告诉我,我会进行编辑。

此外,我们一直在寻找有关如何改进 CocoaPods 的建议,因此如果您有任何问题,请在我们的issue tracker 中提交,以便我们想出解决问题的方法!

编辑

正如 Jack Wu 在 cmets 中的 shown,有一个第三方 CocoaPods 插件可以为您自动执行这些步骤。可以找到here。请注意,它是第三方插件,当 CocoaPods 存在时,可能并不总是更新。另请注意,它是由 CocoaPods 核心团队成员制作的,因此问题不会成为问题。

【讨论】:

  • 感谢上帝的这篇文章。我被这个噩梦搞砸了...stackoverflow.com/questions/9863836/library-not-found-for-lpods,我现在不得不移除 CP。谢谢
  • (在我的情况下 - 2014 年 3 月 - 它与整个“Parse / Facebook 图书馆 / 架构设置”的疯狂有关。可能会帮助某人阅读。再次感谢。)
  • 我即将这样做,原因是它经常需要重新编译所有 Pod 项目,即使它们都没有被触及,所以它大大减慢了我的构建时间。跨度>
  • 要离开这里,因为它对我很有用:github.com/kylef/cocoapods-deintegrate
  • 如果有人想知道为什么 Xcode 中会弹出一百万条警告,那是因为您需要在 git/svn 上提交更改
【解决方案2】:

pod deintegrate 和 pod clean 是从项目/repo 中删除 CocoaPod 的两个指定命令。

这是完整的命令集:

$ sudo gem install cocoapods-deintegrate cocoapods-clean
$ pod deintegrate
$ pod cache clean --all
$ rm Podfile

原始解决方案在这里找到:https://medium.com/@icanhazedit/remove-uninstall-deintegrate-cocoapods-from-your-xcode-ios-project-c4621cee5e42#.wd00fj2e5

pod deintegrate 上的 CocoaPod 文档:https://guides.cocoapods.org/terminal/commands.html#pod_deintegrate

【讨论】:

  • 谢谢,(几乎)为我工作。在这些命令之后,我在编译期间遇到了链接器错误。解决方案是从 Targets->Build Phases->Link Binary With Libraries 中删除“Pods 框架”
  • 自 1.0.0beta8 版本以来,Cocoapods 创建了具有以下名称的奇怪构建阶段:? 检查 Pods Manifest.lock。检查它们是否在 deintegrate 后被删除。
  • 请注意,如果您的机器上没有安装 cocoapods,您需要先执行 gem install cocoapods 才能使用 pod 命令。如果您将项目恢复或复制到新系统上,就会发生这种情况。
  • 我更,rm Podfile.lock
【解决方案3】:

要从项目中完全删除 pod,您需要先安装两个东西...如下(假设您的系统中已经安装了 cocoa-pods。)...

  1. Cocoapods-Deintegrate 插件
  2. Cocoapods-Clean 插件

安装

  1. Cocoapods-Deintegrate 插件

    在您的终端上使用以下命令进行安装。

    sudo gem install cocoapods-deintegrate
    
  2. Cocoapods-清洁插件

    在您的终端上使用以下命令进行安装。

    sudo gem install cocoapods-clean
    

用法

首先使用像往常一样的命令转到您的项目文件夹..

cd (path of the project) //Remove the braces after cd

现在使用这两个插件将其完全删除,如下所示..

  1. Cocoapods-Deintegrate 插件

    在您的终端上使用以下命令首先从您的项目中分离 pod。

     pod deintegrate
    

  1. Cocoapods-清洁插件

    从您的项目中解构 pod 后,在您的终端上使用以下命令彻底清理它。

     pod clean
    

    完成上述任务后,Podfile 应该仍然保留在您的项目目录中..只需手动删除它或在终端上使用以下命令..

     rm Podfile
    

就是这样...现在您的项目已从 pod 中解放出来...已清理。

从系统中移除 Cocoapods。

尝试在终端上使用以下命令从系统中卸载/删除 coca-pods。

sudo gem uninstall cocoapods

它会自动去除古柯豆荚。

谢谢。 希望这会有所帮助。

【讨论】:

  • 哇! pod clean 删除您的工作区,即使您在其中有其他项目!小心!
  • @charl 如果要从单个项目中清理 pod,则必须清除工作区……但该方法显然不适用于与单个工作区关联的多个项目……:(跨度>
  • 这是所有解决方案中最好、最干净的解决方案。 Thnx 伴侣!
【解决方案4】:

我认为有一个更简单的方法来做到这一点。

根据接受的答案编辑,现在您可以使用第三方插件cocoapods-deintegrate,它是可靠的,因为它是由 CocoaPods 核心团队成员制作的。

但是,还有一些文件:

Podfile
Podfile.lock
Workspace

您可以手动将它们从您的项目中删除,但还有另一个工具可以帮助您清理它们,谢谢cocoapods-clean。

最后,卸载工作还没有完成,cocoapods-clean不要清理Podfile,直接运行:

rm Podfile

干杯!

在删除之前,你应该确保你有你的项目的备份!

【讨论】:

  • fwiw 的问题在于 deintegrate 依赖于 gems 和 ruby​​,就像 cocoapods 一样。目前,由于 El Capitan 和宝石的困难,我正在寻找移除豆荚。卸载程序应该作为独立的二进制文件提供。
  • 感谢和更多详细信息here,如果您在成功解体后遇到问题。
  • 感谢使用 'cocoapods-deintegrate' 顺利完成
  • 谢谢,它适用于 macOS Monterey,因为您目前无法安装 cocoapods(很好,对吗?)更多详细信息(但不是解决方案)groups.google.com/g/cocoapods/c/Egpg8Yp6qsY
【解决方案5】:

pod deintegrate

在这个 cmd 之后,您的项目中没有留下任何 Cocoapods 的痕迹。

但是您引用 Pods 项目的工作空间仍然存在,您需要手动删除以下 3 个文件:

xx.xcworkspace
Podifle
Podfile.lock

然后您可以再次使用您的项目。

玩得开心!

测试 CocoaPod 版本 = 1.2.0

【讨论】:

  • 很好,在手动删除了最多的东西后也在这里工作。
  • deintegrate nukes 您的工作区。如果您碰巧需要它,请小心。
  • @mistdon 你第二次救了你的命。
【解决方案6】:

我尝试了所有这些答案,但仍然无法构建,最终我尝试了:

pod deintegrate
pod install

确实有效!

这就像它需要从构建阶段删除所有 pod 脚本并重新添加它们以使其正常工作,至少在我的情况下是这样。

【讨论】:

  • 特别有用,如果您重命名了一个集成了 pod 的项目。
【解决方案7】:

Keith 的回答很棒 - 我只想指出,因为 Cocoapods 0.36 开始支持 Dynamic Frameworks,如果您使用的是“use_frameworks!”在您的“Podfile”中并且您希望删除 Cocoapods,您必须这样做:

  • 在Build Phases 下删除Embed Pods Frameworks 阶段。

【讨论】:

  • 对。如果你不这样做,你会得到构建错误。
  • 如果Build Phases中还有其他处理Pods的文件,也请删除。
【解决方案8】:

开发人员可能面临两个方面。

  • 要么他想从项目中完全删除 pod
  • 开发者想从项目中卸载特定框架 豆荚。

在第一种情况下,您必须使用“pod deintegrate”并按照上述答案中提到的几个步骤进行操作。

对于第二种情况,如果你想卸载安装在你的 pod 文件中的任何特定框架,只需注释你想要卸载的框架并运行 pod install 命令即可。

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'ProjectName' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

    pod 'iCarousel', '~> 1.8'
#    pod 'Facebook-iOS-SDK', '~> 4.1'
#    pod 'ParseFacebookUtilsV4', '~> 1.11'
#    pod 'Parse', '~> 1.14'


end

在这里,我想卸载 facebook 和解析框架(使用 pod 安装)而不是 iCarousel,这就是我像上面一样更新我的 pod 文件的原因。

现在,如果我运行 pod install,它将保留 iCarousel 在我的项目中,并将删除 facebook 并解析。

【讨论】:

    【解决方案9】:

    从终端 cd 移动到项目文件夹。以下步骤有助于从项目中分离 pod

    $ sudo gem install cocoapods-deintegrate cocoapods-clean
    $ pod deintegrate
    $ pod clean
    $ rm Podfile
    

    然后只要打开项目文件并删除 Pod 文件夹,如果它仍然在项目资源管理器中,颜色为红色。构建项目

    【讨论】:

    • 不错的答案,它正在工作....
    【解决方案10】:
    1. 您需要做的第一件事是删除Podfile、Podfile.lock、Pods 文件夹和生成的工作区。
    2. 接下来,在.xcodeproj 中,删除对Pods.xcconfig 文件和libPods.a 文件的引用。
    3. 在 Build Phases 项目选项卡中,删除 Check Pods Manifest.lock 部分(打开)、Copy Pods Resources 部分(底部)和 Embed Pod Resources(底部)。
    4. 删除Pods.framework。

    您可能想要做的唯一一件事就是包含您之前使用的一些库。您可以通过简单地将 pods 文件夹中的任何文件夹拖到您的项目中来做到这一点(我更喜欢将它们放入我的 Supporting Files 文件夹中)。

    它对我有用。

    【讨论】:

      【解决方案11】:
      $ sudo gem install cocoapods-deintegrate cocoapods-clean
      $ pod deintegrate
      $ pod clean
      $ rm Podfile
      

      【讨论】:

      • 除掉所有的cocoapods后gem uninstall cocoapods-deintegrate cocoapods-clean
      【解决方案12】:

      如果不行,试试
      1. 清理项目。
      2. 删除派生数据。

      如果您不知道如何删除派生数据,请转到此处

      How to "Delete derived data" in Xcode6?

      【讨论】:

        【解决方案13】:

        如果您只想删除一个 pod 并保留您可能已安装的其他 pod,请在您的应用目录中打开 podfile 并删除您要删除的那个。然后使用终端导航到您的应用目录并输入:

        pod update
        

        这将删除您从 podfile 中删除的 pod。您会在终端中看到它已被删除:

        Analyzing dependencies
        Removing FirebaseUI
        Removing UICircularProgressRing
        

        请注意,此方法还将拉取任何更新到您的 podfile 中的其他 pod。你可能想要也可能不想要。

        【讨论】:

        • 根据文档,您应该使用 pod install 来添加/删除 pod。这是专门为了避免像您在此处所说的那样进行更新。您可以阅读他们关于这个主题的“指南”的更多信息......guides.cocoapods.org/using/pod-install-vs-update.html
        【解决方案14】:

        删除所有相关的 pod 文件:

        • xx.xcworkspace
        • 播客文件
        • Podfile.lock

        在项目导航器中:

        点击项目名称(蓝色图标)--> Targets (*) --> Build Phases --> 移除“[CP] Check Pods manifests.lock”(点击“x”)

        (*) 点击项目名称,您可能需要先点击“显示项目和目标列表”才能看到侧边栏。

        【讨论】:

        • 我还删除了“Pods”文件夹,因为我只使用了一个,否则只需删除“Pods”文件夹中的单个“NameOfThePod”文件夹。
        【解决方案15】:

        我将简单地写下 iv 所做的事情(从我的项目中删除任何 CocoaPods)..

        1. 删除任何添加的文件夹(框架、Pods、...)
        2. 删除所有添加的文件(PROJECT.xcworkspace、PodFile、PodFile.lock、Pods-PROJECT.debug.xcconfig、Pods-PROJECT.release.xcconfig、...)
        3. 保留您原来的那些(PROJECT、PROJECT_Tests、PROJECT.xcodeproj)
        4. 从 xcode 上的项目中删除框架引用

        要从 xcode 中删除框架引用:

        1. 使用项目导航器
        2. 选择项目
        3. 选择目标项目
        4. 从顶部选项中选择构建阶段
        5. 保留默认组(Target Dependencies、Compile Sources、Linked Binary with Libraries、Copy Bundle Resources)并删除任何其他组

        【讨论】:

          【解决方案16】:
          1. 从.plist 中删除podfile 名称
          2. 再次重新安装 pod (use this link for pod installation)

          【讨论】:

            【解决方案17】:

            我认为你不再需要解体了。我可以在终端中使用以下命令来做到这一点:

            吊舱安装

            它会自动删除不再在 podfile 中的那些

            【讨论】:

              【解决方案18】:

              使用这些终端的命令(不要忘记在新行的开头使用 sudo):

              open:YourDir YouName$ sudo gem uninstall cocoapods
              Password:?
              Remove executables:
                  pod, sandbox-pod
              
              in addition to the gem? [Yn]  Y
              Removing pod
              Removing sandbox-pod
              Successfully uninstalled cocoapods-1.4.0
              open:YourDir YourName$ gem list --local | grep cocoapods
              cocoapods-core (1.4.0)
              cocoapods-deintegrate (1.0.2)
              cocoapods-downloader (1.1.3)
              cocoapods-plugins (1.0.0)
              cocoapods-search (1.0.0)
              cocoapods-stats (1.0.0)
              cocoapods-trunk (1.3.0)
              cocoapods-try (1.1.0)
              

              像这样一一卸载列表:

              open:YourDir YourName$ sudo gem uninstall cocoapods-core
              Successfully uninstalled cocoapods-core-1.4.0
              open:YourDir YourName$ sudo gem uninstall cocoapods-trunk
              Successfully uninstalled cocoapods-trunk-1.3.0
              open:YourDir YourName$ sudo gem uninstall cocoapods-try
              Successfully uninstalled cocoapods-try-1.1.0
              open:YourDir YourName$ gem list --local | grep cocoapods
              open:YourDir YourName$ sudo gem uninstall cocoapods-stats
              Successfully uninstalled cocoapods-stats-1.0.0
              open:YourDir YourName$ sudo gem uninstall cocoapods-search
              Successfully uninstalled cocoapods-search-1.0.0
              open:YourDir YourName$ sudo gem uninstall cocoapods-downloader
              Successfully uninstalled cocoapods-downloader-1.1.3
              open:YourDir YourName$ sudo gem uninstall cocoapods-plugins
              Successfully uninstalled cocoapods-plugins-1.0.0
              open:YourDir YourName$ gem list --local | grep cocoapods
              cocoapods-deintegrate (1.0.2)
              open:YourDir YourName$ sudo gem uninstall cocoapods-deintegrate
              Successfully uninstalled cocoapods-deintegrate-1.0.2
              open:YourDir YourName$ sudo gem uninstall cocoapods-stats
              Successfully uninstalled cocoapods-stats-1.0.0
              open:YourDir YourName$ sudo gem uninstall cocoapods-search
              Successfully uninstalled cocoapods-search-1.0.0
              open:YourDir YourName$ sudo gem uninstall cocoapods-downloader
              Successfully uninstalled cocoapods-downloader-1.1.3
              open:YourDir YourName$ sudo gem uninstall cocoapods-plugins
              Successfully uninstalled cocoapods-plugins-1.0.0
              open:YourDir YourName$ gem list --local | grep cocoapods
              cocoapods-deintegrate (1.0.2)
              open:YourDir YourName$ sudo gem uninstall cocoapods-deintegrate
              Successfully uninstalled cocoapods-deintegrate-1.0.2
              

              【讨论】:

                【解决方案19】:

                我能够使用 CocoaPods 应用程序(版本 1.5.2)删除项目中的 pod。之后我只删除了文件夹中的 podfile、podfile.lock 和 xcworkspace 文件。

                【讨论】:

                  【解决方案20】:

                  图示详细

                  【讨论】:

                    【解决方案21】:

                    提供的所有答案都是有效且正确的。但是,当您运行 pod install 并修改包含任何 cocoapods 配置的任何字段时,clean 和 deintegrate 将按预期停止工作。

                    在我的例子中,我在 构建设置 上覆盖了 FRAMEWORK_SEARCH_PATHS 等,并且在处理 40 个目标时变得乏味......

                    以下 ruby​​ 文件旨在运行 cocoapods 命令以“完全”清理项目,并执行一些额外的清理工作,例如构建设置并从项目中删除“Pod”文件夹等。该脚本还可能包含由“clean”或“deintegrate”执行的操作

                    require 'xcodeproj'
                    
                    ### HELPERS ###
                    # Array extension for non-Ruby rail
                    class Array
                        # Wraps and object into an array
                        #
                        # @param object [Any] The object to be wrapped
                        # @return [Any] The array with the value wrapped. If the object is nil, then returns empty array
                        def self.wrap(object)
                            if object.nil?
                                []
                            elsif object.respond_to?(:to_ary)
                                object.to_ary || [object]
                            else
                                [object]
                          end
                        end
                    end
                    
                    # Performs the cocoapods clean up actions. It will install the dependencies needed.
                    def cocoapod_clean_actions
                        ## DEINTEGRATE
                        puts "** Installing Cocoapods 'DEINTEGRATE' **"
                        system("sudo gem install cocoapods-deintegrate")
                        
                        puts "** Performing Cocoapods 'DEINTEGRATE' **"
                        system("pod deintegrate")
                        
                        ## CLEAN
                        puts "** Installing Cocoapods 'CLEAN' **"
                        system("sudo gem install cocoapods-deintegrate")
                        
                        puts "** Performing Cocoapods 'CLEAN' **"
                        system("pod clean")
                    end
                    
                    # Performs a clean up on the build settings removing all the identified pods leftovers
                    #
                    # @param project [Xcodeproj] Xcode project where to permorm the actions
                    def clean_build_settings(project)
                        puts "** Removing Cocoapods references from 'BUILD SETTING' **"
                        podsOcurrence = "PODS"
                    
                        project.targets.each { |target| 
                            target.build_configurations.each { |build_configuration|
                                puts "Inspecting BUILD_SETTINGS for TARGET => #{target.name} & CONFIGURATION => #{build_configuration.name}"
                                build_settings = build_configuration.build_settings
                                build_settings.each { |key, value|
                                    if key.include?(podsOcurrence)
                                        build_settings.delete(key)
                                    else
                                        clean(build_settings, key, podsOcurrence)
                                    end
                                }
                            }
                        }
                        project.save()
                    end
                    
                    # Performs a clean-up on a specific key of the build settings by removing the occurrences given. It also cleans the value if empty.
                    #
                    # @param build_settings [Hash] Build Settings for a specific target and configuration
                    # @param flag [String] Key to find in the build_settings
                    # @param occurence [String] The occurence to be removed from the value of build settings key
                    def clean(build_settings, flag, occurence)
                        puts "CLEAN => flag = #{flag}, ocurrence = #{occurence}"
                        indexes = Array.new()
                        build_settings_flag = Array.wrap(build_settings[flag])
                        build_settings_flag.each_with_index { |value, index|
                        if value.include?(occurence)
                            previous_index = index - 1
                                if previous_index >= 0 && build_settings_flag[previous_index].to_s&.start_with?("-")
                                    indexes.append(previous_index)
                                end
                                indexes.append(index)
                            end
                        }
                    
                        if indexes.count > 0
                            build_settings_flag.delete_if.with_index { |_, index| 
                                indexes.include? index
                            }
                    
                            # Replace the value for the build setting
                            if build_settings_flag.empty?
                                puts "Removing empty array #{flag}"
                                build_settings.delete(flag)
                            else 
                                puts "Reassining array #{flag}"
                                build_settings[flag] = build_settings_flag
                            end
                        end
                    end
                    
                    # Performs a clean up on the build settings removing all the identified pods leftovers
                    #
                    # @param project [Xcodeproj] Xcode project where to permorm the actions
                    def clean_build_phases(project)
                        puts "** Removing Cocoapods references from 'BUILD_PHASES' **"
                        project.targets.each { |target|
                            #if target.name == "WhiteLabel" #TESTING
                                puts "Inspecting BUILD_PHASES for TARGET => #{target.name}"
                                target.shell_script_build_phases.each { |shell_script| 
                                    if shell_script.name.include?("[CP]")
                                        puts "Removing '#{shell_script.name}' shell script"
                                        shell_script.remove_from_project() 
                                    elsif shell_script.name == "Crashlytics Run Script"
                                        puts "Deleting '#{shell_script.name}'"
                                        # Add extra build phases such as the Crashlytics
                                        #shell_script.remove_from_project()
                                    end
                                }
                                #break #TESTING
                            #end #TESTING
                        }
                        project.save()
                    end
                    
                    # Removes all the unwanted cocoapods files and folders from the project
                    #
                    # @param project [Xcodeproj] Xcode project where to permorm the actions
                    def remove_files_and_folders(project)
                        puts "** Removing Cocoapods files and folders from project **"
                    
                        ## Project
                        # BE CAREFUL WITH GROUP(LINK) NAME AND GROUP PATH(FOLDER)
                        project.groups.find{ |group| group.path == "Pods" }&.remove_from_project()
                        project.save()
                    
                        # File system
                        system('rm -rf Pods')
                        #system('rm Podfile')
                    end
                    
                    
                    ### MAIN ###
                    puts "********** Cocoapods CLEAN UP **********"
                    cocoapod_clean_actions()
                    
                    puts "********** Cocoapods EXTRA CLEAN UP **********"
                    project = Xcodeproj::Project.open "./WhiteLabel.xcodeproj"
                    
                    clean_build_settings(project)
                    clean_build_phases(project)
                    remove_files_and_folders(project)
                    
                    project.save()
                    

                    而且可以调用

                    ruby PodExtraClean.rb
                    

                    【讨论】:

                      猜你喜欢
                      • 1970-01-01
                      • 2021-10-19
                      • 1970-01-01
                      • 2017-02-14
                      • 2019-05-01
                      • 2019-05-29
                      • 2017-07-21
                      • 2015-01-08
                      相关资源
                      最近更新 更多