Enabling third-party libraries (example: AFNetworking) in a static library

Can third-party libraries be included in a static library? Example. Is it possible to include AFNetworking in a static library.

+3
ios xcode static-libraries
Oct 18 '13 at 5:57 on
source share
2 answers

A direct answer to your question: YES, you can definitely enable any third-party library if they expose a public API (a set of headers for you). For AFNetworking, they made it so simple by providing a Cocoapods script so your project could reference it.

But keep in mind that when you release your static library with AFNetwork enabled inside, and someday, if your static lib user decides to use AFNetwork in his own code, the Obj-C compiler will complain about duplicate characters, and it won’t be able to create your project with its own static library.

My advice

My advice: just refer to the link shared by @Amar above. It is very important NOT to include any third-party libraries in your static library if you are hoping to share it with other developers or the community. Always use links for other third-party static libraries instead of including them, for example, use Cocoapods.

+3
Nov 04 '13 at 16:33
source share

Just for completeness, because I think the previous answers / comments give good advice, this is a custom script to include a third-party lib in the output lib of the assembly

set -e set +u TGT_FULLPATH="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_NAME}" TMP_FULLPATH="${BUILT_PRODUCTS_DIR}/original_${EXECUTABLE_NAME}" THIRPARTY_FULLPATH=... ARCHSPECIFIC_THIRDPARTY="${BUILT_PRODUCTS_DIR}/thinThirdparty" # What the architecture for the lib we just built? LIPO_ARCH=$(lipo -info ${TGT_FULLPATH} | awk 'END{ print $NF }') # Create a thirdparty lib only for the current architecture lipo -thin ${LIPO_ARCH} ${THIRPARTY_FULLPATH} -output ${ARCHSPECIFIC_THIRDPARTY} # Join the two libaries mv ${TGT_FULLPATH} ${TMP_FULLPATH} libtool -static -o ${TGT_FULLPATH} ${TMP_FULLPATH} ${ARCHSPECIFIC_THIRDPARTY} 2>&1 >/dev/null # Remove the temp artifacts rm ${TMP_FULLPATH} rm ${ARCHSPECIFIC_THIRDPARTY} 
0
Jan 29 '14 at 9:16
source share



All Articles