andpdas
andpdas

Reputation: 37

Creating a framework for iOS in XCode 4.2

I am trying to create a framework in XCode 4.2 for iOS applications.

I was developing my own Game framework. I was usually distributing only in source codes and resources but, due to using ARC in my framework, I had to distribute in static library and framework.

I haven't decided which shall I use yet. Although developing framework for iOS is not a supported way, It's better that distributing resources and headers and Mach-O file in one directory(same as framework).

So I want to use framework to distribute my Game framework. I used this script to create a Framework. It seems that I have success creating a framework and copy mach-O and headers and resources. But this framework's resources couldn't be added to the application which I added this framework.

#!/bin/bash 

set -o errexit
set -o nounset

# Environment Variables
PANKIA_DIR="${SRCROOT}/Pankia"
PANKIA_CORE_DIR="${PANKIA_DIR}/Core"
PANKIA_PLATFORM_DIR="${PANKIA_DIR}/Platform"

FRAMEWORK_NAME="Pankia"
FRAMEWORK_VERSION=A
FRAMEWORK_VERSION_NUMBER=1.0
FRAMEWORK_BUILD_PATH="${SRCROOT}/build/${CONFIGURATION}-framework"
FRAMEWORK_DIR="${FRAMEWORK_BUILD_PATH}/${FRAMEWORK_NAME}.framework"
FRAMEWORK_PACKAGE_NAME="${FRAMEWORK_NAME}.${FRAMEWORK_VERSION_NUMBER}.zip"
FRAMEWORK_TARGET_NAME="libPankia"

# Clean directories
rm -rf "${FRAMEWORK_BUILD_PATH}"

# Build simulator and device binaries.
xcodebuild -project ${PROJECT_NAME}.xcodeproj -sdk iphonesimulator${IPHONEOS_DEPLOYMENT_TARGET} -target ${FRAMEWORK_TARGET_NAME} -configuration ${CONFIGURATION} clean build
xcodebuild -project ${PROJECT_NAME}.xcodeproj -sdk iphoneos${IPHONEOS_DEPLOYMENT_TARGET} -target ${FRAMEWORK_TARGET_NAME} -configuration ${CONFIGURATION} clean build

# create framework directories.
mkdir -p ${FRAMEWORK_DIR}
mkdir -p ${FRAMEWORK_DIR}/Versions
mkdir -p ${FRAMEWORK_DIR}/Versions/${FRAMEWORK_VERSION}
mkdir -p ${FRAMEWORK_DIR}/Versions/${FRAMEWORK_VERSION}/Resources
mkdir -p ${FRAMEWORK_DIR}/Versions/${FRAMEWORK_VERSION}/Headers

# create symlinks
ln -s ${FRAMEWORK_DIR}/Versions/${FRAMEWORK_VERSION} ${FRAMEWORK_DIR}/Versions/Current
ln -s ${FRAMEWORK_DIR}/Versions/Current/Headers ${FRAMEWORK_DIR}/Headers
ln -s ${FRAMEWORK_DIR}/Versions/Current/Resources ${FRAMEWORK_DIR}/Resources
ln -s ${FRAMEWORK_DIR}/Versions/Current/${FRAMEWORK_NAME} ${FRAMEWORK_DIR}/${FRAMEWORK_NAME}

# create the universal library
lipo ${SRCROOT}/build/${CONFIGURATION}-iphoneos/lib${FRAMEWORK_TARGET_NAME}.a ${SRCROOT}/build/${CONFIGURATION}-iphonesimulator/lib${FRAMEWORK_TARGET_NAME}.a -create -output "${FRAMEWORK_DIR}/Versions/Current/${FRAMEWORK_NAME}"

# copy files
cp ${PANKIA_PLATFORM_DIR}/GameInterface/Pankia.h ${FRAMEWORK_DIR}/Headers/
cp ${PANKIA_PLATFORM_DIR}/Models/Native/*.h ${FRAMEWORK_DIR}/Headers/
cp ${PANKIA_CORE_DIR}/Models/Native/*.h ${FRAMEWORK_DIR}/Headers/

cp -r ${PANKIA_PLATFORM_DIR}/Resources ${FRAMEWORK_DIR}/Resources/
cp -r ${PANKIA_PLATFORM_DIR}/RetinaResources ${FRAMEWORK_DIR}/Resources/
cp ${SRCROOT}/libPankia/Info.plist ${FRAMEWORK_DIR}/Resources/

# cp ${SRCROOT}/build/${CONFIGURATION}-iphoneos/usr/local/include/*.h ${FRAMEWORK_DIR}/Headers/

# cp Info.plist ${FRAMEWORK_DIR}/Resources

# zip (配布用に TestFramework.framework ディレクトリをZIP圧縮するだけなので、配布しないなら以下はコメントアウトしてもよい)
# cd ${FRAMEWORK_BUILD_PATH}
# zip -ry ${FRAMEWORK_PACKAGE_NAME} $(basename $FRAMEWORK_DIR)

Do you know why?

And is there any better way to distribute my framework?

Upvotes: 2

Views: 8273

Answers (1)

beyerss
beyerss

Reputation: 1352

Here is a helpful tutorial on creating frameworks. I have used it and have been able to package resources with the framework.

http://codefriend.blogspot.com/2011/09/creating-ios-framework-with-xcode4.html

Upvotes: 7

Related Questions