iOS调用动态库运行报错dyld: Library not loaded

dyld: Library not loaded: @executable_path/testdylib.dylib
  Referenced from: /private/var/mobile/Containers/Bundle/Application/79BEC832-780C-4AFE-9018-04833F140108/TSArm.app/TSArm
  Reason: no suitable image found.  Did find:
/private/var/mobile/Containers/Bundle/Application/79BEC832-780C-4AFE-9018-04833F140108/TSArm.app/testdylib.dylib: mmap() error 1 at address=0x00178000, size=0x00001000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Bundle/Application/79BEC832-780C-4AFE-9018-04833F140108/TSArm.app/testdylib.dylib
/private/var/mobile/Containers/Bundle/Application/79BEC832-780C-4AFE-9018-04833F140108/TSArm.app/testdylib.dylib: mmap() error 1 at address=0x0017B000, size=0x00001000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Bundle/Application/79BEC832-780C-4AFE-9018-04833F140108/TSArm.app/testdylib.dylib


原因:dylib库文件不会在打包时签名,而iPhone6安全机制改变,强制检查动态库签名问题。
可以使用命令查看:

$ codesign -dvvv /xxx/xxxx

解决方案:
A、使用静态库
B、在Build Phase中添加如下签名的脚本



install_name_tool -change testdylib.dylib @loader_path/testdylib.dylib ${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}
echo
'path: ' ${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}

#this is the list of binaries we have to sign for beeing able to run un-jailbroken
LIST_BINARY_EXTENSIONS= "dylib so 0 vis pvr"

export CODESIGN_ALLOCATE=`xcodebuild -find codesign_allocate`

GEN_ENTITLEMENTS=
"/Users/zhangjg/src/gen_entitlements.py"

if [ ! -f ${GEN_ENTITLEMENTS} ]; then
echo
"error: $GEN_ENTITLEMENTS not found. Codesign won't work."
exit -1
fi

if [
"${PLATFORM_NAME}" == "iphoneos" ]; then
${GEN_ENTITLEMENTS} 
"com.trustmobi.TSArm" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent" ;
codesign -v -f -s
"iPhone Developer" --entitlements "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/"

#if user has set a code_sign_identity different from iPhone Developer we do a real codesign (for deployment on non-jailbroken devices)
if ! [ -z "${CODE_SIGN_IDENTITY}" ] && [ "${CODE_SIGN_IDENTITY}" != "iPhone Developer" ] && [ "${CODE_SIGN_IDENTITY}" != "Don't Code Sign"   ]; then
echo Doing a full bundle sign using genuine identity
"${CODE_SIGN_IDENTITY}"
for binext in $LIST_BINARY_EXTENSIONS
do
codesign -fvvv -s
"${CODE_SIGN_IDENTITY}" -i com.trustmobi.TSArm `find ${CODESIGNING_FOLDER_PATH} -name "*.$binext" -type f` ${CODESIGNING_FOLDER_PATH}
done
echo In case your app crashes with SIG_SIGN check the variable LIST_BINARY_EXTENSIONS in tools/darwin/Support/Codesign.command
fi
fi


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值