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


当前回答

删除所有相关pod文件:

xx.xc工作区 子文件 Podfile.lock

在Project Navigator中:

点击项目名称(蓝色图标)—> Targets(*)—> Build Phases—> Remove”[CP] Check Pods清单。(点击“x”)

(*)点击项目名称,你可能必须先点击“显示项目和目标列表”才能看到侧栏。

其他回答

我尝试了所有这些答案,但它仍然不会建立,最终我尝试了:

pod deintegrate
pod install

这真的有效!

就好像它需要从构建阶段删除所有的pod脚本,然后重新添加它们才能工作,至少在我的情况下是这样。

使用这些终端的命令(不要忘记在新行开始使用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

删除所有相关pod文件:

xx.xc工作区 子文件 Podfile.lock

在Project Navigator中:

点击项目名称(蓝色图标)—> Targets(*)—> Build Phases—> Remove”[CP] Check Pods清单。(点击“x”)

(*)点击项目名称,你可能必须先点击“显示项目和目标列表”才能看到侧栏。

所提供的答案均正确有效。但是,当您运行pod安装和修改任何包含cocoapods配置的字段时,clean和deintegration将停止正常工作。

在我的情况下,我有,除其他FRAMEWORK_SEARCH_PATHS覆盖在构建设置和它变得乏味时,处理40个目标…

下面的ruby文件打算运行cocoapods命令来“完全”清理项目,并执行一些额外的清理,例如Build设置,并从项目中删除“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

我觉得你不需要再分解了。我可以在终端中使用以下命令做到这一点:

正在安装

它会自动删除那些不在播客文件中的