美文网首页
ios 多工程化

ios 多工程化

作者: 那是一阵清风_徐来 | 来源:发表于2019-12-25 17:13 被阅读0次

一、添加多工程

  • 新建

待续...

  • 多工程静态库连接问题注意事项
    • 1、在其他工程中,load 方法不调用问题

    • 解决方案
      在对应主工程project -> targets -> build setting. -> other linker flag 设置:-all_load 或者 -ObjC,其中区别自己补充;

      该该操作是为了设置编译链接;也可以在其他主工程里面调用 其他的工程【因为你没使用到任何一个库的函数,因此链接的时候会被忽略掉的】

    • 2、库文件导入#import <xxxx/xxxx.h>不会自动提示

      • 解决方案
        在对应主工程project -> targets -> build setting. -> header search paths 设置:$(SRCROOT)/../xxxx,其中xxxx 为子工程名字,该操作主要为设置路径
    • 3、文件导入#import <xxxx/xxxx.h>报错,提示找不到该文件

      • 解决方案
        在对应主工程project -> targets -> build phrase. -> headers ,把需要在其他工程调用的类设置:public,然后在该静态库的 .h文件中导入#import <XXXX/xxxx.h>

二、cocopods管理多工程

1、Podfile 使用

去官网查看Podfile 用户,上面介绍了多工程的使用

  • cocopods 官网使用方法

  • 示例

    # Uncomment the next line to define a global platform for your project
    # 学习博客: https://www.jianshu.com/p/7d0ad4cde012
    # 官网Podfile: https://guides.cocoapods.org/using/the-podfile.html
    
    source 'https://github.com/CocoaPods/Specs.git'
    source 'https://github.com/Artsy/Specs.git'
    
    platform :ios, '9.0'
    
    #忽略Pods警告
    inhibit_all_warnings!
    
    #设置工作空间文件名
    workspace 'MineAppProject.xcworkspace'
    
    #通用pods集
    def commonPods
      # Pods someFile
      pod 'YYKit', '~> 1.0.9'
      pod 'MGJRouter'
      pod 'AFNetworking', '~> 3.0'
      pod 'MJExtension', '~> 3.0.15.1'
      pod 'Masonry'
    end
    
    target 'QFUIKit' do
      use_frameworks!
      commonPods
      project 'QFUIKit/QFUIKit.xcodeproj'
    
      target 'QFUIKitTests' do
        inherit! :search_paths
      end
    end
    
    target 'CommonComponent' do
      use_frameworks!
      commonPods
      project 'CommonComponent/CommonComponent.xcodeproj'
    
      target 'CommonComponentTests' do
        inherit! :search_paths
      end
    end
    
    target 'BackgroundControlComponent' do
      use_frameworks!
      commonPods
      project 'BackgroundControlComponent/BackgroundControlComponent.xcodeproj'
    
      target 'BackgroundControlComponentTests' do
        inherit! :search_paths
        # Pods for testing
      end
    
    end
    
    target 'MineApp' do
      use_frameworks!
      commonPods
      project 'MineApp/MineApp.xcodeproj'
    
      target 'MineAppTests' do
        inherit! :search_paths
        # Pods for testing
      end
      
      target 'MineAppUITests' do
        inherit! :search_paths
        # Pods for testing
      end
    end
    
    
  • 多工程cocopods注意事项

    • 1、警告
    [!] The `MineApp [Debug]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `../Pods/Target Support Files/Pods-MineApp/Pods-MineApp.debug.xcconfig'. This can lead to problems with the CocoaPods installation
      - Use the `$(inherited)` flag, or
      - Remove the build settings from the target.
    
    • 解决方案
      在对应project -> targets -> build setting. ->header search path 导入:$(inherited)

    • 2、警告

    add a target to the Podfile that embeds these frameworks to make this message go away (e.g. a test target).
    
    • 解决方案
      静态库需添加一个测试工程,否则有上述警告警告

      target 'xxxxxxTests' do
      inherit! :search_paths
      end
      
    • 3、警告

    [!] Could not automatically select an Xcode project. Specify one in your Podfile like so:
    
      project 'path/to/Project.xcodeproj'
    
    • 解决方案
      需导入 工程路径 xcodeproj【否则:会报错无法自动选择Xcode项目。在Podfile中指定一个路径: project 'xxxxx/xxxxx.xcodeproj'】

      target 'MineApp' do
      use_frameworks!
      
      #主工程路径 xcodeproj【否则:会报错无法自动选择Xcode项目。在Podfile中指定一个路径】
      project 'xxxxx/xxxxx.xcodeproj'
      
      end
      
    • 4、警告

      Library not loaded: @rpath/AFNetworking.framework
      
      • 解决方案
        在对应project -> targets -> build setting. -> Mach-O Type 导入:Static Library

相关文章

网友评论

      本文标题:ios 多工程化

      本文链接:https://www.haomeiwen.com/subject/gscofqtx.html