iOS Framework问题:Class都在两者中实现

时间:2022-01-19 17:19:57

I'm working on an iOS framework project which is using a third-party framework classes so I added third-party framework under Linked frameworks and libraries section.

我正在开发一个使用第三方框架类的iOS框架项目,所以我在Linked frameworks和libraries部分添加了第三方框架。

When I add my custom framework in my iOS app project, I'm getting this warning for each class

当我在我的iOS应用程序项目中添加自定义框架时,我会收到每个类的警告

objc[3139]: Class 'class_name' is implemented in both /private/var/containers/Bundle/Application/C131AF0F-7CF8-4360-8716-3E8A595169D6/'app_name'.app/Frameworks/'framework_name'.framework/'framework_name' and /var/containers/Bundle/Application/C131AF0F-7CF8-4360-8716-3E8A595169D6/'app_name'.app/'app_name'. One of the two will be used. Which one is undefined.

objc [3139]:类'class_name'在/private/var/containers/Bundle/Application/C131AF0F-7CF8-4360-8716-3E8A595169D6/'app_name'.app/Frameworks/'framework_name'.framework/'framework_name中实现'和/var/containers/Bundle/Application/C131AF0F-7CF8-4360-8716-3E8A595169D6/'app_name'.app/'app_name'。将使用两者之一。哪一个未定义。

iOS app project is also linked with that third-party framework. So I think getting this issue because my framework also contains compiled version of third-party framework.

iOS应用程序项目也与该第三方框架相关联。所以我认为这个问题是因为我的框架还包含第三方框架的编译版本。

I didn't find any proper solution for this. Can anyone tell me how to get rid of this?

我没有找到任何适当的解决方案。谁能告诉我如何摆脱这个?

Is there any way i can make it work?

有什么办法可以让它发挥作用吗?

1 个解决方案

#1


2  

tl;dr Don't link the third-party framework in your application target's Build Phases. Use Link Frameworks Automatically instead.

tl; dr请勿在应用程序目标的Build Phases中链接第三方框架。请改用自动链接框架。


To make this a little more clear, let me give an example. There is a third-party framework called CrashReporter.framework. The custom framework is called HockeySDK.framework (which links to CrashReporter.framework). Then I have my application called WeatherApp (which links to HockeySDK.framework).

为了使这一点更清楚,让我举一个例子。有一个名为CrashReporter.framework的第三方框架。自定义框架称为HockeySDK.framework(链接到CrashReporter.framework)。然后我有一个名为WeatherApp的应用程序(链接到HockeySDK.framework)。

CrashReporter.framework  <---
    ^                        |
    |                        |
    |                      X X X   NO! DONT'T LINK THIS!
HockeySDK.framework          |
    ^                        |
    |                        |
    |                        |
WeatherApp  -----------------

I do not link CrashReporter.framework in the Link Binary With Libraries section of Build Phases in the WeatherApp target (even though Weather app needs CrashReproter.framework to build). I go to the Build Settings of the WeatherApp target and ensure Link Frameworks Automatically (and Enable Modules (C and Objective-C) if on iOS) is set to Yes.

我没有在WeatherApp目标中的Build Binses的Link Binary With Libraries部分链接CrashReporter.framework(即使Weather应用程序需要CrashReproter.framework来构建)。我转到WeatherApp目标的构建设置并确保自动链接框架(如果在iOS上,则启用模块(C和Objective-C))设置为是。

#1


2  

tl;dr Don't link the third-party framework in your application target's Build Phases. Use Link Frameworks Automatically instead.

tl; dr请勿在应用程序目标的Build Phases中链接第三方框架。请改用自动链接框架。


To make this a little more clear, let me give an example. There is a third-party framework called CrashReporter.framework. The custom framework is called HockeySDK.framework (which links to CrashReporter.framework). Then I have my application called WeatherApp (which links to HockeySDK.framework).

为了使这一点更清楚,让我举一个例子。有一个名为CrashReporter.framework的第三方框架。自定义框架称为HockeySDK.framework(链接到CrashReporter.framework)。然后我有一个名为WeatherApp的应用程序(链接到HockeySDK.framework)。

CrashReporter.framework  <---
    ^                        |
    |                        |
    |                      X X X   NO! DONT'T LINK THIS!
HockeySDK.framework          |
    ^                        |
    |                        |
    |                        |
WeatherApp  -----------------

I do not link CrashReporter.framework in the Link Binary With Libraries section of Build Phases in the WeatherApp target (even though Weather app needs CrashReproter.framework to build). I go to the Build Settings of the WeatherApp target and ensure Link Frameworks Automatically (and Enable Modules (C and Objective-C) if on iOS) is set to Yes.

我没有在WeatherApp目标中的Build Binses的Link Binary With Libraries部分链接CrashReporter.framework(即使Weather应用程序需要CrashReproter.framework来构建)。我转到WeatherApp目标的构建设置并确保自动链接框架(如果在iOS上,则启用模块(C和Objective-C))设置为是。