Using Cocoapods libraries in Flutter iOS platform specific code

23.1k Views Asked by At

I'm trying to use a Cocoapods library (for an external SDK) but I haven't found any documentation to do it. I've already integrated it in the Android part by just adding a line to the Gradle file.

Simply, I would like to create (or maybe find) a podfile where I could add my dependency and use it in AppDelegate.swift file.

What I tried so far is run pod init in ios/ folder and then add my pod (pod 'Charts' for example) and run pod install but it says:

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target Runner to Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig or include the Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig in your build configuration (Flutter/Release.xcconfig).

And then when I try to build on Xcode, it gives me this error:

error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

I think I'm doing it the right way and I've found nothing to help me on Flutter.io documentation.

Thanks in advance for your help!

3

There are 3 best solutions below

3
On BEST ANSWER

After you run pod init and pod install in the ios/ folder, add

#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"

to ios/Flutter/Debug.xcconfig

and add

#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"

to ios/Flutter/Release.xcconfig

1
On

Did you add your project target to your Podfile? Something like that:

def swift_frameworks
  pod 'PodName', 'X.X'
end


target 'My Project' do
  swift_frameworks
end
0
On

Just put your pods at the end of Podfile file which is under the ios folder, like:

pod 'UMCAnalytics'

By default there are some codes in this file but just ignore them and add your pod to below them. After that, run:

pod update 

then you will see the pods installed.