ChatGPT解决这个技术问题 Extra ChatGPT

How to remove CocoaPods from a project?

What's the right way of removing CocoaPods from a project? I want to remove the whole CocoaPod. Due to some limitations imposed by my client I can't use it. I need to have just one xcodeproj instead of an xcworkspace.

And remember: next time use git and just roll it back!
Run pod deintegrate
Follow steps in this link medium.com/app-makers/…

K
Keith Smiley

Removing CocoaPods from a project is possible, but not currently automated by the CLI. First thing, if the only issue you have is not being able to use an xcworkspace you can use CocoaPods with just xcodeprojs by using the --no-integrate flag which will produce the Pods.xcodeproj but not a workspace. Then you can add this xcodeproj as a subproject to your main xcodeproj.

If you really want to remove all CocoaPods integration you need to do a few things:

NOTE editing some of these things if done incorrectly could break your main project. I strongly encourage you to check your projects into source control just in case. Also these instructions are for CocoaPods version 0.39.0, they could change with new versions.

Delete the standalone files (Podfile Podfile.lock and your Pods directory) Delete the generated xcworkspace Open your xcodeproj file, delete the references to Pods.xcconfig and libPods.a (in the Frameworks group) Under your Build Phases delete the Copy Pods Resources, Embed Pods Frameworks and Check Pods Manifest.lock phases. This may seem obvious but you'll need to integrate the 3rd party libraries some other way or remove references to them from your code.

After those steps you should be set with a single xcodeproj that existed before you integrated CocoaPods. If I missed anything let me know and I will edit this.

Also we're always looking for suggestions for how to improve CocoaPods so if you have an issues please submit them in our issue tracker so we can come up with a way to fix them!

EDIT

As shown by Jack Wu in the comments there is a third party CocoaPods plugin that can automate these steps for you. It can be found here. Note that it is a third party plugin and might not always be updated when CocoaPods is. Also note that it is made by a CocoaPods core team member so that problem won't be a problem.


Thank God for this post. I got screwed by this nightmare... stackoverflow.com/questions/9863836/library-not-found-for-lpods and I've had to remove CP for now. Thanks
(In my case - March 2014 - it related to the whole "Parse / Facebook liraries / architecture settings" madness. Might help someone reading. Again thanks.)
I'm about to do this and the reason is that it regularly needs to recompile all of the Pod projects even though none of them have been touched, so it has slowed my build times considerably.
Going to leave this here because it worked great for me: github.com/kylef/cocoapods-deintegrate
If anyone is wondering why a million warnings are popping up in Xcode, it's because you need to commit your changes on git/svn
B
BadPirate

pod deintegrate and pod clean are two designated commands to remove CocoaPod from your project/repo.

Here is the complete set of commands:

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

The original solution was found here: https://medium.com/@icanhazedit/remove-uninstall-deintegrate-cocoapods-from-your-xcode-ios-project-c4621cee5e42#.wd00fj2e5

CocoaPod documentation on pod deintegrate: https://guides.cocoapods.org/terminal/commands.html#pod_deintegrate


thanks, works (nearly) for me. After these commands i got a linker error during compilation. Solution was to remove the "Pods framework" from Targets->Build Phases->Link Binary With Libraries
Since version 1.0.0beta8 Cocoapods create strange Build Phases with such names: 📦 Check Pods Manifest.lock. Check if they are removed after deintegrate.
Please note that if you are on a machine that has not had cocoapods installed, you'll need to do gem install cocoapods before the pod command will work. This can happen if you restore or copy a project onto a new system.
I more, rm Podfile.lock
Also need to remove the ".xcworkspace" file since it is no longer needed. Just use XCode to open the ".xcodeproj" file.
o
onCompletion

To remove pods from a project completely you need to install two thing first...those are follows(Assuming you have already cocoa-pods installed in your system.)...

Cocoapods-Deintegrate Plugin Cocoapods-Clean Plugin

Installation

Cocoapods-Deintegrate Plugin Use this following command on your terminal to install it. sudo gem install cocoapods-deintegrate 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

Now use those two plugins to remove it completely as follows..

Cocoapods-Deintegrate Plugin Use this following command on your terminal to deintegrate the pods from your project first. pod deintegrate

https://i.stack.imgur.com/TGgrf.png

Cocoapods-Clean Plugin After deintegration of pod from your project use this following command on your terminal to clean it completely. pod clean After completing the above tasks there should be the Podfile still remaining on your project directory..Just delete that manually or use this following command on the terminal.. 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

It will remove the coca-pods automatically.

Thanks. Hope this helped.


Whoa! pod clean deletes your workspace, even if you have other projects in it! Be careful!
@charl In case of cleaning pods from your single project you have to clear the workspace...but the method obviously not applicable for multiple projects associated with the single workspace....:(
This was the best and clean solution among all. Thnx Mate!
C
Crashalot

I think there's a more easy way to do that.

As edited by the accepted answer, now you can use a third party plugin cocoapods-deintegrate, it's reliable because its made by a CocoaPods core team member.

But,there're still some files remain:

Podfile
Podfile.lock
Workspace

You could remove them from your project manually,but there's also another tool for helping you to clean them, thanks cocoapods-clean.

Finally, the uninstallation work is still not completed, cocoapods-clean don't clean the Podfile, just run:

rm Podfile

Cheers!

Before removing you should ensure you have a backup of your project!


fwiw the problem with deintegrate is that it relies on gems and ruby, just like cocoapods. Currently I'm looking to remove pods because of difficulties with El Capitan and gems. Uninstallers ought to be available as stand-alone binaries.
Thanks and more details here if you run into issues after a successful deintegrate.
Thanks that was smooth using 'cocoapods-deintegrate'
Thanks, it works on macOS Monterey, because you currently can't install cocoapods (great, right?) more details (but not the solution) groups.google.com/g/cocoapods/c/Egpg8Yp6qsY
m
mistdon

pod deintegrate

After this cmd, no traces of Cocoapods left in your project.

But your workspace referencing the Pods project still remains, you need to should remove below 3 files manually:

xx.xcworkspace Podifle Podfile.lock

Then you can use your project again.

Have fun!

Test CocoaPod version = 1.2.0


Nice, also worked here after already having deleted the most stuff by hand.
deintegrate nukes your workspace. Be careful if you happen to need it.
@mistdon you saved y life second time.
D
David Rees

I tried all these answers but it still wouldn't build, eventually I tried:

pod deintegrate
pod install

which actually worked!

It's like it needs to remove all the pod scripts from your build phases and re-add them back in for it to work, at least in my case.


Specially helpful, if you renamed a project with pods integrated.
N
Neha Vipin

From terminal cd to move to the project folder. The below steps help to de-integrate the pod from the project

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

Then just open the project file and remove the Pod folder if it is still on the Project Explorer with red color. Build the project... It's ready to go!!!


Nice answer, it's working ....
Works perfectly. Thanks
S
Serlite

Keith's answer is great - I just want to point out that because Cocoapods 0.36 is starting to support Dynamic Frameworks, if you are using 'use_frameworks!' in your 'Podfile' and you wish to remove the Cocoapods, you must do this:

Under Build Phases delete Embed Pods Frameworks phase.


Right. If you don't do this, you will get build errors.
If there are any other files dealing with Pods inside of Build Phases delete them too.
A
Aditya

There can be two aspects developer may face.

Either he wants to remove pods completely from project

developer wants to uninstall particular framework from project from pods.

In first case you have to use 'pod deintegrate' and follow several steps which are mentioned in the answers above.

For second case that is if you want to uninstall any particular framework which is installed there very simple way available in your pod file just comment the framework which you want to uninstall and run pod install command.

# 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

Here I want to uninstall facebook and parse frameworks (which were installed using pods) and not iCarousel that is why I have updated my pod file like above.

Now if I run pod install it will keep iCarousel as it is in my project and will remove facebook and parse.


s
sudo make install

The first thing that you will need to do is remove the Podfile, Podfile.lock, the Pods folder, and the generated workspace. Next, in the .xcodeproj, remove the references to the Pods.xcconfig files and the libPods.a file. Within the Build Phases project tab, delete the Check Pods Manifest.lock section (open), Copy Pods Resources section (bottom) and Embed Pod Resources(bottom). Remove Pods.framework.

The only thing you may want to do is include some of the libraries that you were using before. You can do this by simply draging whatever folders where in the pods folders into your project (I prefer to put them into my Supporting Files folder).

It worked for me.


d
double-beep
$ sudo gem install cocoapods-deintegrate cocoapods-clean
$ pod deintegrate
$ pod clean
$ rm Podfile

After getting rid of all of the cocoapods gem uninstall cocoapods-deintegrate cocoapods-clean
C
Community

If not work, try 1. clean the project. 2. deleted derived data. if you don't know how to delete derived data go here

How to "Delete derived data" in Xcode6?


T
TM Lynch

If you just want to remove one pod and keep others you may have installed, open the podfile in your app directory and delete the one you want to remove. Then navigate to your app directory using terminal and type:

pod update

This will remove the pod you removed from the podfile. You will see it has been removed in the terminal:

Analyzing dependencies
Removing FirebaseUI
Removing UICircularProgressRing

Note that this method will also pull any updates to the other pods in your podfile. You may or may not want that.


Per the documentation, you should use pod install for adding/removing pods. This is specifically to avoid updating like you said here. You can read more on their 'Guides' on this very topic... guides.cocoapods.org/using/pod-install-vs-update.html
N
Neph

Delete all related pod files:

xx.xcworkspace

Podfile

Podfile.lock

and in the Project Navigator:

Click on the project name (blue icon) --> Targets (*) --> Build Phases --> Remove "[CP] Check Pods manifests.lock" (click on the "x")

(*) Click on the project name, you might have to click on "Show project and target list" to see the side bar first.


I also deleted the "Pods" folder because I was only using a single one, otherwise just delete the single "NameOfThePod" folder inside the "Pods" folder.
S
SoliQuiD

I am gonna write what iv done very briefly (to delete any CocoaPods from my project)..

delete any added folder (frameworks, Pods,...) delete any added files (PROJECT.xcworkspace, PodFile, PodFile.lock, Pods-PROJECT.debug.xcconfig, Pods-PROJECT.release.xcconfig,...) just leave your original ones (PROJECT, PROJECT_Tests, PROJECT.xcodeproj) remove framework reference from the project on xcode

To remove the framework reference from xcode:

Use the Project Navigator Select Project Select Target PROJECT Select Build Phases from the top options leave the default groups (Target Dependencies, Compile Sources, Linked Binary with Libraries, Copy Bundle Resources) and delete any other


K
Kampai

Remove the podfile name from .plist Reinstall the pod again (use this link for pod installation)


Ö
Özgür Cem Birler

I don't think you need to deintegrate anymore. I was able to do it with the following command in terminal:

pod install

and it automatically removed the ones that are no longer in the podfile


C
CrownFord

Use these Terminal's commands (Don't forget to use sudo at the beginning of new lines):

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)

Uninstall the list one by one like this:

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

B
Berkant

I was able to remove my pods in the project using the CocoaPods app (Version 1.5.2). Afterwards I only deleted the podfile, podfile.lock and xcworkspace files in the folder.


v
vilas deshmukh

https://i.stack.imgur.com/hq3D8.png

pictorial representation detailed


R
Reimond Hill

All the answers provided are valid and correct. However, when you run pod install and modify any of the fields containing any cocoapods configuration, clean and deintegrate stop working as expected.

In my case, I had, among others FRAMEWORK_SEARCH_PATHS overwritten on the Build Settings and it gets tedious when dealing with 40 targets...

https://i.stack.imgur.com/EAoAl.png

https://i.stack.imgur.com/pb7Zn.png

The following ruby file intends to run the cocoapods commands to "fully" clean the project and it performs some extra clean up such as Build settings and removes the "Pod" folder from the project among others. The script might also contain actions performed by "clean" or "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()

And it can be called

ruby PodExtraClean.rb