在 Flutter iOS 平台特定代码中使用 Cocoapods 库

Using Cocoapods libraries in Flutter iOS platform specific code

我正在尝试使用 Cocoapods 库(用于外部 SDK),但我没有找到任何相关文档。我已经将它集成到 Android 部分,只需在 Gradle 文件中添加一行即可。

简单地说,我想创建(或者可能找到)一个 podfile,我可以在其中添加我的依赖项并在 AppDelegate.swift 文件中使用它。

到目前为止我尝试的是 运行 pod initios/ 文件夹中,然后添加我的 pod(例如 pod 'Charts')和 运行 pod install 但它说:

[!] 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).

然后当我尝试在 Xcode 上构建时,它给了我这个错误:

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

我认为我的做法是正确的,但在 Flutter.io 文档方面我没有找到任何可以帮助我的东西。

在此先感谢您的帮助!

您是否将项目目标添加到 Podfile? 类似的东西:

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


target 'My Project' do
  swift_frameworks
end

在运行pod initpod install之后在ios/文件夹中添加

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

ios/Flutter/Debug.xcconfig

并添加

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

ios/Flutter/Release.xcconfig

只需将 pods 放在 ios 文件夹下 Podfile 文件的末尾,例如:

pod 'UMCAnalytics'

默认情况下,此文件中有一些代码,但只需忽略它们并将您的广告连播添加到它们下面。之后,运行:

pod update 

然后您将看到 pods 安装。