iOS Architecture - Static Library. framework relies on third-party libraries

Needs Analysis:

    Encapsulate your own capabilities as static libraries for customers to use, but there are some job markets that already do well
Open code, or low-cost solutions, allows us to use technology that others have made public or purchased at a low cost.The same is true for making static libraries, and sometimes we need to rely on mature third-party libraries to serve us.So how do you rely on third-party libraries to make your own static library, framework ni?

target

Demonstrates a project that relies on a third-party library, YYModel, to make a.framework based on the previous.framework authoring basics.
But I don't want to package the YYModel into my static library because it already exists in the project and needs to be managed through Cocoapods.

Experimental steps

iOS Architecture - Static Library. Resource File Packaging bundle for framework (6) , we use the previous static library project.

  1. The first step is to go to the project directory on the terminal cd and execute the pod init to generate the Podfile file
Last login: Fri Apr 26 18:22:52 on ttys003
lzz-Mac-mini:~ suning$ cd /Users/suning/Desktop/VideoPlayerFramework/MySDK 
lzz-Mac-mini:MySDK suning$ pod init
fatal: Needed a single revision
lzz-Mac-mini:MySDK suning$ 

Result:

2. Modify the Podfile file file, add the third-party library YYModel, terminal execution: pod install, generate the MySDK.xcworkspace management file, and open it from scratch.: use_frameworks in Podfile! To comment.Otherwise, the synthesized.framework cannot be used.

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

use_frameworks!

target 'MySDK' do
   pod 'YYModel'
end
  1. To reference YYModel, simply import the header file and use the method in YYModel:
    : To import at.m.Otherwise, packages typed with script files always show that the files cannot be found.
    However, packages using Xcode Aggregate are normally packaged after.h import.
    I don't know why for the moment.
#import "ShowInfo.h"
#import "Student.h"
#import <YYModel/YYModel.h>

@implementation ShowInfo

+ (void)show {
    NSLog(@"-----ShowInfo------");
    Student *hhh =  [Student yy_modelWithDictionary:@{@"name":@"LiLei"}];
    NSLog(@"-----hhh%@------",hhh.name);
}

    
+ (MyViewController *)creatMyViewController {
    MyViewController * myVC =[[MyViewController alloc]init];
    return myVC;
}

@end

4. Two packaging methods: using Xcode Aggregate to package stand-alone script files
First: Xcode Aggregate packaging, direct copy of script content

#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${PROJECT_DIR}/${CONFIGURATION}-universal
WORKSPACE_NAME=${PROJECT_NAME}.xcworkspace
# make sure the output directory exists 
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphoneos ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean

xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean


xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphoneos ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" build

xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" build

# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"

# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"

Second: self-built script file packaging

#!/bin/sh

#project name
PROJECT_NAME=MySDK
WORKSPACE_NAME=${PROJECT_NAME}.xcworkspace

#Project Path
PROJECT_DIR=$(pwd)

#Folder path after build
BUILD_DIR=$PROJECT_DIR/Build/Products
BUILD_ROOT=$PROJECT_DIR/Build/Products

#Packaging mode Debug/Release defaults to Release
development_mode=Debug

UNIVERSAL_OUTPUTFOLDER=${PROJECT_DIR}/${development_mode}-universal
INSTALL_DIR_A=${PROJECT_DIR}/${PROJECT_NAME}.framework/${PROJECT_NAME}


# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"


# Step 1. Build Device and Simulator versions
xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${development_mode} -sdk iphoneos ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean

xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${development_mode} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean


xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${development_mode} -sdk iphoneos ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" build

xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${development_mode} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" build


# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${development_mode}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"


# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${development_mode}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"

echo "======End of synthesis======"

# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"

# -f Determines whether a file exists
if [ -f "${INSTALL_DIR_A}" ]
then
echo "======Verify the package is successful======"
lipo -info "${INSTALL_DIR_A}"
fi

#Open Target Folder
open "${PROJECT_DIR}"

Script2.sh Was modified from a previous script.The compiled code was modified because it was managed using Cocoapods.Note the contrast.

5. Packaged Target File

6. demo validation, to validate demo, use Cocoapods management, create a new Podfile, rely on YYModel, otherwise YYModel.h will not be found

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

use_frameworks!

target 'MySDK' do
   pod 'YYModel'
end
  1. Use examples
  2. Run Results

    Both packages succeeded in the end.This makes the static library. framework, which relies on third-party library YYModel, a success!

Further research on reference packaging between static libraries.a,.framework will continue.

Keywords: SDK iOS Mac xcode

Added by CodeToad on Wed, 15 May 2019 13:22:06 +0300