美文网首页
iOS MPGSDK.framework生成经历

iOS MPGSDK.framework生成经历

作者: 東玖零 | 来源:发表于2021-09-23 16:01 被阅读0次

    在之前的文章中提到使用3DS支付最终是要下载源码编译得到MPGSDK.framework的。

    常规操作,打开MPGSDK.xcodeproj工程。

    1、编辑配置将debug改为release
    2、选中Any iOS Divce
    3、然后command+B
    4、再去编译文件Release-iphoneos目录找到MPGSDK.framework,这就是真机库。


    WX20210923-145825@2x.png

    5、重复上面的步骤,将第2步选中一个模拟器,需要把arm64 排除在外。

    build settings->excluded architectures  加入arm64架构,
    这是把arm64 排除在外,这样到处的framework 用lipo -info 查询是不包含arm64
    

    得到了Release-iphonesimulator文件夹中的MPGSDK.framework,这就是模拟器库。

    xcode 13 生成库路径为:

    /Users/adong/Documents/workspace/gateway-ios-sdk/DerivedData/MPGSDK/Build/Products
    
    正确合并方法

    1.将Release-iphoneos、Release-iphonesimulator文件复制到A文件夹中。
    2.再在A文件夹下创建framework文件夹。
    3.将Release-iphoneos中的MPGSDK.framework复制到framework中。
    4.使用如下命令进行合并。

    lipo -create framework/MPGSDK.framework/MPGSDK Release-iphonesimulator/MPGSDK.framework/MPGSDK -output framework/MPGSDK.framework/MPGSDK
    

    5.再需要把framework中Release-iphonesimulator/MPGSDK.framework/Modules/MPGSDK.swiftmodule的文件全都拷贝到合并的framework/MPGSDK.framework/Modules/MPGSDK.swiftmodule中,如有文件夹同名,将同名下的文件拷贝过去。


    WX20210923-180037@2x.png

    将合并之后的库拖到工程,点击运行,断点直接就卡住了。

    Library not loaded: @rpath/MPGSDK.framework/MPGSDK
      Referenced from: /Users/adong/Library/Developer/CoreSimulator/Devices/F3991045-28ED-4703-B624-77449D5D1AE7/data/Containers/Bundle/Application/5D559727-10EB-445D-8067-EADA28DE257C/ProjectName.app/ProjectName
      Reason: tried: '/Users/adong/Documents/workspace/ios/ProjectNamement-ios/DerivedData/ProjectName/Build/Products/Debug-iphonesimulator/MPGSDK.framework/MPGSDK' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/MPGSDK.framework/MPGSDK' (no such file), '/usr/lib/swift/MPGSDK.framework/MPGSDK' (no such file), '/Users/adong/Library/Developer/CoreSimulator/Devices/F3991045-28ED-4703-B624-77449D5D1AE7/data/Containers/Bundle/Application/5D559727-10EB-445D-8067-EADA28DE257C/ProjectName.app/Frameworks/MPGSDK.framework/MPGSDK' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/MPGSDK.framework/MPGSDK' (no such file), '/usr/lib/swift/MPGSDK.framework/MPGSDK' (no such file), '/Users/adong/Library/Developer/CoreSimulator/Devices/F3991045-28ED-4703-B624-77449D5D1AE7/data/Containers/Bundle/Application/5D559727-10EB-445D-8067-EADA28DE257C/ProjectName.app/Frameworks/MPGSDK.framework/MPGSDK' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/MPGSDK.framework/MPGSDK' (no such file)
    Library not loaded: @rpath/MPGSDK.framework/MPGSDK
      Referenced from: /Users/adong/Library/Developer/CoreSimulator/Devices/F3991045-28ED-4703-B624-77449D5D1AE7/data/Containers/Bundle/Application/5D559727-10EB-445D-8067-EADA28DE257C/ProjectName.app/ProjectName
      Reason: tried: '/Users/adong/Documents/workspace/ios/ProjectNamement-ios/DerivedData/ProjectName/Build/Products/Debug-iphonesimulator/MPGSDK.framework/MPGSDK' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/MPGSDK.framework/MPGSDK' (no such file), '/usr/lib/swift/MPGSDK.framework/MPGSDK' (no such file), '/Users/adong/Library/Developer/CoreSimulator/Devices/F3991045-28ED-4703-B624-77449D5D1AE7/data/Containers/Bundle/Application/5D559727-10EB-445D-8067-EADA28DE257C/ProjectName.app/Frameworks/MPGSDK.framework/MPGSDK' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library
    

    看到这种错误最开始想到就是配置里的other link flag 使用load_all,其实不用,找到配置中的MPGSDK.framework引用地方将frameworks, Libraries, and Enbedded Content的 Do Not Endbed改为Embed & Sign即可。


    WX20210923-151444@2x.png

    这时候就模拟器就可以正常运行了,真机也可以运行了,打包也正常了。

    错误合并方法遇到了各种问题

    再将这先将真机库拖到A文件中,再将模拟库拖到A文件中,就会得到一个提示是替换还是合并(后面实验得知此方法是错误的,因为使用lipo -info 查看控制台没有输出armv7,后面的报错就对了)。

    这时候我们选择合并,就得到了真机和模拟合并的库,
    但打包就报了一堆的错误如下:

    ld: warning: ignoring file /Users/adong/Documents/workspace/ios/ProjectNamement-ios/Library/MPG/MPGSDK.framework/MPGSDK, missing required architecture armv7 in file /Users/adong/Documents/workspace/ios/ProjectNamement-ios/Library/MPG/MPGSDK.framework/MPGSDK (3 slices)
    Undefined symbols for architecture armv7:
      "nominal type descriptor for MPGSDK.Gateway", referenced from:
          _got.$s6MPGSDK7GatewayCMn in MPGBindingCreditCard.o
      "nominal type descriptor for MPGSDK.Gateway3DSecureViewController", referenced from:
          _got.$s6MPGSDK29Gateway3DSecureViewControllerCMn in MPGBindingCreditCard.o
      "MPGSDK.GatewayRegion.asiaPacific.unsafeMutableAddressor : MPGSDK.GatewayRegion", referenced from:
          ProjectName.MPGBindingCreditCard.init() -> ProjectName.MPGBindingCreditCard in MPGBindingCreditCard.o
      "nominal type descriptor for MPGSDK.GatewayResult", referenced from:
          _got.$s6MPGSDK13GatewayResultOMn in ProjectNameTestData.o
      "protocol conformance descriptor for MPGSDK.GatewayMap : Swift.Decodable in MPGSDK", referenced from:
          lazy protocol witness table accessor for type MPGSDK.GatewayMap and conformance MPGSDK.GatewayMap : Swift.Decodable in MPGSDK in MerchantAPI.o
      "MPGSDK.GatewayRegion.china.unsafeMutableAddressor : MPGSDK.GatewayRegion", referenced from:
          function signature specialization <Arg[0] = Dead> of ProjectName.ProjectNameTestData.gateway() -> () in ProjectNameTestData.o
      "MPGSDK.GatewayMap.subscript.setter : (at: Swift.String) -> Any?", referenced from:
          ProjectName.MerchantAPI.check3DSEnrollment(transaction: ProjectName.Transaction, redirectURL: Swift.String, completion: (ProjectName.Result<MPGSDK.GatewayMap>) -> ()) -> () in MerchantAPI.o
          ProjectName.MerchantAPI.completeSession(transaction: ProjectName.Transaction, completion: (ProjectName.Result<MPGSDK.GatewayMap>) -> ()) -> () in MerchantAPI.o
          function signature specialization <Arg[0] = Dead> of ProjectName.ProjectNameTestData.gateway() -> () in ProjectNameTestData.o
          ProjectName.MPGBindingCreditCard.updateWithPayerData() -> () in MPGBindingCreditCard.o
      "protocol conformance descriptor for MPGSDK.GatewayMap : Swift.Encodable in MPGSDK", referenced from:
          lazy protocol witness table accessor for type MPGSDK.GatewayMap and conformance MPGSDK.GatewayMap : Swift.Encodable in MPGSDK in MerchantAPI.o
      "MPGSDK.GatewayMap.subscript.getter : (at: Swift.String) -> Any?", referenced from:
          ProjectName.MPGBindingCreditCard.check3DSEnrollmentV46Handler(ProjectName.Result<MPGSDK.GatewayMap>) -> () in MPGBindingCreditCard.o
          ProjectName.MPGBindingCreditCard.check3DSEnrollmentv47Handler(ProjectName.Result<MPGSDK.GatewayMap>) -> () in MPGBindingCreditCard.o
          closure #1 () -> () in ProjectName.MPGBindingCreditCard.handle3DS(authView: MPGSDK.Gateway3DSecureViewController, result: MPGSDK.Gateway3DSecureResult) -> () in MPGBindingCreditCard.o
          ProjectName.MPGBindingCreditCard.processPaymentHandler(result: ProjectName.Result<MPGSDK.GatewayMap>) -> () in MPGBindingCreditCard.o
          partial apply forwarder for closure #1 () -> () in closure #1 (ProjectName.Result<MPGSDK.GatewayMap>) -> () in ProjectName.MPGBindingCreditCard.createSession(nameOnCard: Swift.String, cardNumber: Swift.String, expiryMM: Swift.String, expiryYY: Swift.String, cvv: Swift.String) -> () in MPGBindingCreditCard.o
      "nominal type descriptor for MPGSDK.GatewayMap", referenced from:
          _got.$s6MPGSDK10GatewayMapVMn in MerchantAPI.o
      "type metadata for MPGSDK.GatewayMap", referenced from:
          ProjectName.MerchantAPI.(issueRequest in _17CEE51348B79F0B5AFD630801E7D093)(path: Swift.String, method: Swift.String, query: [Foundation.URLQueryItem]?, body: MPGSDK.GatewayMap?, completion: (ProjectName.Result<MPGSDK.GatewayMap>) -> ()) -> () in MerchantAPI.o
          generic specialization <MPGSDK.GatewayMap> of closure #1 (Foundation.Data?, __C.NSURLResponse?, Swift.Error?) -> () in ProjectName.MerchantAPI.(responseHandler in _17CEE51348B79F0B5AFD630801E7D093)<A where A: Swift.Decodable>((ProjectName.Result<A>) -> ()) -> (Foundation.Data?, __C.NSURLResponse?, Swift.Error?) -> () in MerchantAPI.o
          lazy protocol witness table accessor for type MPGSDK.GatewayMap and conformance MPGSDK.GatewayMap : Swift.Encodable in MPGSDK in MerchantAPI.o
          lazy protocol witness table accessor for type MPGSDK.GatewayMap and conformance MPGSDK.GatewayMap : Swift.Decodable in MPGSDK in MerchantAPI.o
      "type metadata accessor for MPGSDK.Gateway3DSecureViewController", referenced from:
          ProjectName.MPGBindingCreditCard.(begin3DSAuth in _8D4103D69EB0F7CB8C1010517B08ADF5)(simple: Swift.String) -> () in MPGBindingCreditCard.o
      "MPGSDK.GatewayMap.subscript.setter : (Swift.String) -> Any?", referenced from:
          ProjectName.MerchantAPI.(issueRequest in _17CEE51348B79F0B5AFD630801E7D093)(path: Swift.String, method: Swift.String, query: [Foundation.URLQueryItem]?, body: MPGSDK.GatewayMap?, completion: (ProjectName.Result<MPGSDK.GatewayMap>) -> ()) -> () in MerchantAPI.o
      "MPGSDK.Gateway.init(region: MPGSDK.GatewayRegion, merchantId: Swift.String) -> MPGSDK.Gateway", referenced from:
          function signature specialization <Arg[0] = Dead> of ProjectName.ProjectNameTestData.gateway() -> () in ProjectNameTestData.o
          ProjectName.MPGBindingCreditCard.init() -> ProjectName.MPGBindingCreditCard in MPGBindingCreditCard.o
      "MPGSDK.GatewayMap.init([Swift.String : Any]) -> MPGSDK.GatewayMap", referenced from:
          ProjectName.MerchantAPI.check3DSEnrollment(transaction: ProjectName.Transaction, redirectURL: Swift.String, completion: (ProjectName.Result<MPGSDK.GatewayMap>) -> ()) -> () in MerchantAPI.o
          ProjectName.MerchantAPI.completeSession(transaction: ProjectName.Transaction, completion: (ProjectName.Result<MPGSDK.GatewayMap>) -> ()) -> () in MerchantAPI.o
      "MPGSDK.GatewayMap.init() -> MPGSDK.GatewayMap", referenced from:
          ProjectName.MerchantAPI.(issueRequest in _17CEE51348B79F0B5AFD630801E7D093)(path: Swift.String, method: Swift.String, query: [Foundation.URLQueryItem]?, body: MPGSDK.GatewayMap?, completion: (ProjectName.Result<MPGSDK.GatewayMap>) -> ()) -> () in MerchantAPI.o
          function signature specialization <Arg[0] = Dead> of ProjectName.ProjectNameTestData.gateway() -> () in ProjectNameTestData.o
          ProjectName.MPGBindingCreditCard.updateWithPayerData() -> () in MPGBindingCreditCard.o
      "nominal type descriptor for MPGSDK.Gateway3DSecureResult", referenced from:
          _got.$s6MPGSDK21Gateway3DSecureResultOMn in MPGBindingCreditCard.o
      "type metadata accessor for MPGSDK.Gateway", referenced from:
          function signature specialization <Arg[0] = Dead> of ProjectName.ProjectNameTestData.gateway() -> () in ProjectNameTestData.o
          ProjectName.MPGBindingCreditCard.init() -> ProjectName.MPGBindingCreditCard in MPGBindingCreditCard.o
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    看到这种问题,我是一头两个大!!!!!

    找到一条关键信息 ld: symbol(s) not found for architecture armv7,说是没有找到支持armv7的库。

    编译真机选的是Any iOS Divce后面还跟着 arm64和armv7的文字呢。没有深研究,我在配置项目里单独输入了armv7同样打了一个包出来了。

    使用命令进行合并参照

    lipo -create 真机路径 模拟器路径 -output 真机路径
    

    真机路径 /Users/adong/Desktop/test/Release-iphoneos/MPGSDK.framework/MPGSDK

    模拟器路径类似

    重新将合并了2次的库的拖到工程里,正常打包,但安装到真机,一打开就闪退,连真机运行卡在启动页面就崩了,可能是没有安上面的参照把其他文件合并过来。

    报错如下:

    * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x409900009e10)
      * frame #0: 0x0000000185107f44 libsystem_platform.dylib`_platform_strlen + 4
        frame #1: 0x000000018520152c libdyld.dylib`objc_opt::objc_stringhash_t::getIndex(char const*) const + 32
        frame #2: 0x00000001852012e4 libdyld.dylib`_dyld_get_objc_selector + 60
        frame #3: 0x0000000185135874 libobjc.A.dylib`search_builtins(char const*) + 112
        frame #4: 0x000000018513567c libobjc.A.dylib`__sel_registerName(char const*, bool, bool) + 44
        frame #5: 0x0000000185127694 libobjc.A.dylib`fixupMethodList(method_list_t*, bool, bool) + 160
        frame #6: 0x000000018512536c libobjc.A.dylib`prepareMethodLists(objc_class*, method_list_t**, int, bool, bool) + 132
        frame #7: 0x00000001851247ac libobjc.A.dylib`realizeClassWithoutSwift(objc_class*, objc_class*) + 1412
        frame #8: 0x0000000185124370 libobjc.A.dylib`realizeClassWithoutSwift(objc_class*, objc_class*) + 328
        frame #9: 0x0000000185138a0c libobjc.A.dylib`map_images_nolock + 5052
        frame #10: 0x0000000185129a6c libobjc.A.dylib`map_images + 96
        frame #11: 0x0000000102d9cf88 dyld`dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) + 1644
        frame #12: 0x0000000102d9d180 dyld`dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) + 76
        frame #13: 0x0000000185201288 libdyld.dylib`_dyld_objc_notify_register + 144
        frame #14: 0x0000000185139a98 libobjc.A.dylib`_objc_init + 1132
        frame #15: 0x0000000102e7a3d0 libdispatch.dylib`_os_object_init + 16
        frame #16: 0x0000000102e89020 libdispatch.dylib`libdispatch_init + 372
        frame #17: 0x00000001b92cc888 libSystem.B.dylib`libSystem_initializer + 200
        frame #18: 0x0000000102dae1b8 dyld`ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 428
        frame #19: 0x0000000102dae58c dyld`ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 52
        frame #20: 0x0000000102da95d0 dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 548
        frame #21: 0x0000000102da953c dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 400
        frame #22: 0x0000000102da8334 dyld`ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 184
        frame #23: 0x0000000102da83fc dyld`ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 92
        frame #24: 0x0000000102d9a3d0 dyld`dyld::initializeMainExecutable() + 136
        frame #25: 0x0000000102d9edb4 dyld`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 4616
        frame #26: 0x0000000102d99208 dyld`dyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, unsigned long*) + 396
        frame #27: 0x0000000102d99038 dyld`_dyld_start + 56
    

    相关文章

      网友评论

          本文标题:iOS MPGSDK.framework生成经历

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