如何从项目中删除CocoaPods ?

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

498564 次浏览

从项目中删除CocoaPods是可能的,但目前还没有被CLI自动化。首先,如果你唯一的问题是不能使用xcworkspace,你可以使用CocoaPods和xcodeprojs,使用--no-integrate标志,这将产生Pods.xcodeproj,而不是一个工作区。然后您可以将这个xcodeproj作为子项目添加到您的主项目xcodeproj中。

如果你真的想移除所有CocoaPods集成,你需要做几件事:

请注意编辑这些东西,如果做得不正确,可能会破坏你的主要项目。我强烈建议您将项目纳入源代码控制,以防万一。此外,这些指令适用于CocoaPods版本0.39.0,它们可能会随着新版本而改变。

  1. 删除独立文件(Podfile Podfile.lock和您的Pods目录)
  2. 删除生成的xcworkspace
  3. 打开你的xcodeproj文件,删除对Pods.xcconfiglibPods.a的引用(在Frameworks组中)
  4. 在你的Build Phases下删除Copy Pods ResourcesEmbed Pods FrameworksCheck Pods Manifest.lock阶段。
  5. 这似乎是显而易见的,但您需要以其他方式集成第三方库,或者从代码中删除对它们的引用。

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

此外,我们一直在寻找关于如何改进CocoaPods的建议,所以如果你有问题,请在我们的问题跟踪器中提交,这样我们就可以想出解决它们的方法!

编辑

正如Jack Wu在评论中所写的所示,有一个第三方CocoaPods插件可以为你自动化这些步骤。可以找到在这里。注意,它是第三方插件,可能并不总是在CocoaPods更新时更新。还要注意,它是由CocoaPods核心团队成员制作的,所以这个问题不会成为问题。

我觉得有更简单的方法。

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

但是,仍然有一些文件遗留下来:

Podfile
Podfile.lock
Workspace

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

最后,卸载工作仍未完成,cocoapods-clean不要清理Podfile,只需运行:

rm Podfile

干杯!

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

Keith的回答很好-我只是想指出,因为Cocoapods 0.36开始支持动态框架,如果你使用'use_frameworks!,并且你希望移除Cocoapods,你必须这样做:

  • Build Phases下删除Embed Pods Frameworks阶段。
  1. 您需要做的第一件事是删除PodfilePodfile.lockPods文件夹和生成的工作区。
  2. 接下来,在.xcodeproj中,删除对Pods.xcconfig文件和libPods.a文件的引用。
  3. 在Build Phases项目选项卡中,删除Check Pods清单。锁定部分(打开),复制Pods资源部分(底部)和嵌入Pod资源(底部)。
  4. 删除# EYZ0。

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

这对我很管用。

要从项目中完全删除pod,你需要先安装两件事…这些是以下(假设你已经在你的系统中安装了可可荚)…

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

安装

  1. < p > Cocoapods-Deintegrate插件

    在您的终端上使用以下命令来安装它。

    sudo gem install cocoapods-deintegrate
    
  2. Cocoapods-Clean Plugin

    Use this following command on your terminal to install it.

    sudo gem install cocoapods-clean
    

Usage

First of all goto your project folder by using the as usual command like..

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

现在使用这两个插件完全删除它如下..

  1. < p > Cocoapods-Deintegrate插件

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

     pod deintegrate
    

Deintegrating Pods

  1. Cocoapods-Clean Plugin

    After deintegration of pod from your project use this following command on your terminal to clean it completely.

     pod clean
    

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

     rm Podfile
    

Thats it...Now you have your project free from pods...Cleaned.

Removing Cocoapods from the system.

Any way try to use the following command on your terminal to uninstall/remove the coca-pods from your system.

sudo gem uninstall cocoapods

它会自动去除可乐皮。

< p >谢谢。

pod deintegratepod 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

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

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

pod deintegrate
pod install

这真的有效!

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

我要写什么iv做的很简单(删除任何CocoaPods从我的项目)..

  1. 删除任何已添加的文件夹(框架,Pods,…)
  2. 删除任何添加的文件(PROJECT.)xcworkspace PodFile PodFile锁,pod - project .debug.xcconfig, pod - project .release.xcconfig…
  3. 只需保留您原来的(PROJECT, PROJECT_Tests, PROJECT.xcodeproj)
  4. 从xcode的项目中删除框架引用

从xcode中删除框架引用:

  1. 使用项目导航器
  2. 选择项目
  3. 选择目标项目
  4. 从顶部选项中选择Build Phases
  5. 保留默认组(目标依赖项、编译源、带有库的链接二进制文件、复制Bundle资源)并删除其他组
  1. .plist中删除podfile名称
  2. 重新安装吊舱(使用此链接安装吊舱)

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

.删除派生数据 如果你不知道如何删除派生数据,请到这里

如何“;删除派生数据”;在Xcode6吗?< / >

开发者可能面临两个方面的问题。

  • 要么他想把舱完全从项目中移除
  • 开发人员想从项目中卸载特定的框架 李豆荚。< / >

在第一种情况下,你必须使用“豆荚分解”,并遵循以上答案中提到的几个步骤。

第二种情况是,如果你想卸载安装在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和解析框架(使用pods安装),而不是iCarousel,这就是为什么我像上面那样更新了我的pod文件。

现在如果我运行pod安装,它将保持iCarousel,因为它是在我的项目,并将删除facebook和解析。

< p > <代码> 豆荚去积分 < /代码> < / p >

在此cmd后,在您的项目中没有Cocoapods的痕迹。

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

< p > # EYZ0 < br > # EYZ0 < br > Podfile.lock < / em >

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

玩得开心!

测试CocoaPod版本= 1.2.0

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

在Project Navigator中:

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

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

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

pod update

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

Analyzing dependencies
Removing FirebaseUI
Removing UICircularProgressRing

注意,这个方法也会拉出podfile中其他pod的任何更新。你可能想要也可能不想要。

我可以使用CocoaPods应用程序(版本1.5.2)在项目中删除我的豆荚。之后我只删除了podfile, podfile。锁定文件夹中的xcworkspace文件。

enter image description here

详细的图形表示

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

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

圆荚体安装

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

从终端cd移动到项目文件夹。下面的步骤有助于将pod从项目中分离出来

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

然后只需打开项目文件,并删除Pod文件夹,如果它仍然在项目资源管理器的红色。构建项目……它准备好了!!

所提供的答案均正确有效。但是,当您运行圆荚体安装并修改包含任何cocoapods配置的任何字段时,清理和分解将停止正常工作。

在我的例子中,我有FRAMEWORK_SEARCH_PATHS覆盖在建立设置上,当处理40个目标时,它变得乏味……

enter image description here

enter image description here

下面的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

如何从你的项目Xcode中删除pod

打开项目目录,然后运行脚本

$ pod deintegrate
$ pod clean
$ rm Podfile

然后必须手动删除.xcworkspace扩展文件

"ProjectName.xcworkspace"

或通过脚本删除

$ rm projectname.xcworkspace