【问题标题】:ObjectiveC framework not export some classesObjective C 框架不导出某些类
【发布时间】:2018-06-09 15:48:34
【问题描述】:

我开发了一个名为 EzoRed (ezored.com) 的工具。它使用本机代码 (c++) 为 ios 或 android 生成 aar 框架。

当我得到生成的 xcode 项目并将其拖放到我的示例项目中时,我可以毫无问题地使用该框架。当我只拖动生成的框架时(使用 Debug 版本的框架一切正常,但使用 Release 无法正常工作。),我的应用程序编译,安装在设备或模拟器上,但是当我运行时出现错误:

我使用 nm 工具检查导出的符号,发现只导出了 *Impl 类。见:

nm -gU build/ios/Release-universal/EzoRed.framework/EzoRed

0000000000010a88 S _OBJC_CLASS_$_EZRAudioStreamerPlatformServiceImpl
0000000000010b28 S _OBJC_CLASS_$_EZRGreetingMessagePlatformServiceImpl
00000000000109e8 S _OBJC_CLASS_$_EZRHttpClientPlatformServiceImpl
0000000000010ab0 S _OBJC_METACLASS_$_EZRAudioStreamerPlatformServiceImpl
0000000000010b50 S _OBJC_METACLASS_$_EZRGreetingMessagePlatformServiceImpl
0000000000010a10 S _OBJC_METACLASS_$_EZRHttpClientPlatformServiceImpl
0000000000010d30 D __ZTIPU39objcproto28EZRHttpClientPlatformService11objc_object
0000000000010fa0 D __ZTIPU42objcproto31EZRAudioStreamerPlatformService11objc_object
0000000000011200 D __ZTIPU44objcproto33EZRGreetingMessagePlatformService11objc_object
0000000000010d18 D __ZTIU39objcproto28EZRHttpClientPlatformService11objc_object
0000000000010f88 D __ZTIU42objcproto31EZRAudioStreamerPlatformService11objc_object
00000000000111e8 D __ZTIU44objcproto33EZRGreetingMessagePlatformService11objc_object
000000000000c700 S __ZTSPU39objcproto28EZRHttpClientPlatformService11objc_object
000000000000c9c0 S __ZTSPU42objcproto31EZRAudioStreamerPlatformService11objc_object
000000000000cca0 S __ZTSPU44objcproto33EZRGreetingMessagePlatformService11objc_object
000000000000c740 S __ZTSU39objcproto28EZRHttpClientPlatformService11objc_object
000000000000ca00 S __ZTSU42objcproto31EZRAudioStreamerPlatformService11objc_object
000000000000cce0 S __ZTSU44objcproto33EZRGreetingMessagePlatformService11objc_object

这很奇怪,因为一切编译都没有问题。

使用 Debug 版本的框架,一切正常。但是 Release 不起作用。

一些检查:

它包含在桥文件中: https://github.com/ezored/sample-app/blob/master/source/ios/SampleApp/SampleApp/SampleApp-Bridging-Header.h

它在 CMakeLists.txt 上:
https://github.com/ezored/sample-app/blob/master/vendor/target-ios-master/CMakeLists.txt#L132

它编译和安装没有问题,但不能运行。它显示向上消息。

所有项目文件都在这里,任何人都可以下载运行:
https://github.com/ezored/sample-app

使用的命令有:

cmake --build . --config Debug  (is exported all files correct)
cmake --build . --config Release  (is exported only *Impl files)

xcode直接命令效果一样:

xcodebuild build -configuration "Debug"  (is exported all files correct)
xcodebuild build -configuration "Release"  (is exported only *Impl files)

我做错了什么?感谢您的帮助。

【问题讨论】:

    标签: c++ ios objective-c xcode frameworks


    【解决方案1】:

    我找到的解决方案放在我的 CMakeLists.txt 行:

    CXX_VISIBILITY_PRESET 默认

    因为文件 ios.cmake 我有以下几行:

    set(CMAKE_CXX_FLAGS "${XCODE_IOS_PLATFORM_VERSION_FLAGS} ${BITCODE} -fvisibility=hidden -fvisibility-inlines-hidden -fobjc-abi-version=2 -fobjc-arc ${CXX_FLAGS}")

    https://github.com/ezored/target-ios/blob/master/build/files/ios.cmake#L284

    我不知道这是否是最佳实践,我会尝试用它在 App Store 上验证应用程序。

    【讨论】:

      猜你喜欢
      • 2011-09-07
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多