繁体   English   中英

无法找到使用主应用程序目标构建自己的框架目标的正确方法

[英]Can't find the right way to build my own framework target with my main app target

我决定在iOS小部件中将我的主项目分为两部分以重用代码。

因此,我在xcworkspace(可可触摸框架)中创建了一个新的目标文件。 这两个目标都有一些共同的Pod依赖关系,我无法确定正确的构建方式。

Xcode目标

第一次尝试:

在podfile中,我为两个目标都指定了所需的pod,但是在构建时,我遇到了多个错误

Foo类在MyApp和MyFramework中都实现。 将使用两者之一。 哪一个未定义。

第二次尝试:

然后,我尝试将框架目标放到主应用程序目标中(就像我们通常使用测试目标一样)

target 'MyApp' do
    main_pods
    app_pods

    target 'MyFramework' do
        inherit! :search_paths

        target 'MyFrameworkTests' do
            inherit! :search_paths
            testing_pods
        end
    end
end

但是,由于没有找到依赖关系,因此框架无法构建。示例:

没有这样的模块Firebase

注意事项

要构建我的主要目标,我必须先构建框架目标,否则找不到“ MyFramework”模块。 当我建立主要目标时,无法同时建立两者吗?

我还有一个应用程序,在其中我在一个单独的项目中创建了一个框架,但是在同一工作区中。 我使用pod来获取所有外部库,并通过将其添加到Xcode的Embedded Binaries中将自己的框架嵌入到应用程序的目标中。 我的Podfile看起来像这样:

workspace 'MyApp'

abstract_target 'BasePods' do
    use_frameworks!

    pod 'Alamofire', '~> 4.4'
    pod 'PromiseKit', '~> 4.1'
    project '../MyAppProject/MyApp/MyApp.xcodeproj'

    target 'MyApp'
    target 'MyAppDevelopment'
end

target 'MyAppCore' do
  use_frameworks!

    pod 'Alamofire', '~> 4.4'
    pod 'PromiseKit', '~> 4.1'
    project '../MyAppProject/MyAppCore/MyAppCore.xcodeproj'

      target 'MyAppCoreTests' do
    inherit! :search_paths
    end
end

在这里,我会创建两个单独的pod目标-一个用于应用程序,另一个用于框架。 我将它们拆分,因为它们位于不同的目录中。

知道了,我有静态库框架依赖性,iOS链接器不支持动态库的静态库依赖性。

CF问题: https//github.com/CocoaPods/CocoaPods/issues/7126

我已经通过Podfile通过以上问题中发布的解决方法解决了它:

post_install do |installer|
    sharedLibrary = installer.aggregate_targets.find { |aggregate_target| aggregate_target.name == 'Pods-SampleFramework' }
    installer.aggregate_targets.each do |aggregate_target|
        if aggregate_target.name == 'Pods-SampleApp'
            aggregate_target.xcconfigs.each do |config_name, config_file|
                sharedLibraryPodTargets = sharedLibrary.pod_targets
                aggregate_target.pod_targets.select { |pod_target| sharedLibraryPodTargets.include?(pod_target) }.each do |pod_target|
                    pod_target.specs.each do |spec|
                        frameworkPaths = unless spec.attributes_hash['ios'].nil? then spec.attributes_hash['ios']['vendored_frameworks'] else spec.attributes_hash['vendored_frameworks'] end || Set.new
                        frameworkNames = Array(frameworkPaths).map(&:to_s).map do |filename|
                            extension = File.extname filename
                            File.basename filename, extension
                        end
                        frameworkNames.each do |name|
                            puts "Removing #{name} from OTHER_LDFLAGS"
                            config_file.frameworks.delete(name)
                        end
                    end
                end
                xcconfig_path = aggregate_target.xcconfig_path(config_name)
                config_file.save_as(xcconfig_path)
            end
        end
    end
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM