如何在 Ionic/Cordova 构建中正确引用 iOS 第 3 方框架,这样它就不会抛出 dyld: Library not loaded: @rpath 错误
How to properly reference an iOS 3rd party framework in Ionic/Cordova build so it doesn't throw dyld: Library not loaded: @rpath error
我有一个使用插件的 Ionic5 (cli 6.3.0)/Cordova 9.0.3 (cordova-lib@9.0.2) 项目。
我正在尝试为第 3 方框架创建自定义插件。
我知道插件的框架是正确的,因为我是用 Plugman 创建的,在添加框架之前我可以 build/run 并从 "coolMethod" 得到 运行 的反馈=43=] 文件.
即使在添加框架之后,我也可以通过 ionic cordova plugin add ./packages/cordova-plugin-my-custom-stuff
正确安装插件
我可以 Ionic/Cordova 使用 ionic cordova build ios
成功构建 iOS 项目
但是当我尝试从 Ionic 命令行 ionic cordova run ios
或自动生成的 xCode 项目 运行 iOS 模拟器时,我得到
dyld: Library not loaded: @rpath/MyThirdPartySDK.framework/MyThirdPartySDK
Referenced from: /Users/myUser/Library/Developer/CoreSimulator/Devices/C9E28EFF-B017-4F5E-
BA89-5200AE5D64EA/data/Containers/Bundle/Application/775C8394-B014-4B01-89CA-
1D462FD54F4A/MyName Mobile-UAT.app/MyName Mobile-UAT
Reason: image not found
项目的结构(为清楚起见进行了压缩)如下所示:
MyProject
-node_modules
-packages
-cordova-plugin-my-custom-stuff
-src
-ios
MyCustomStuff.m
-MyThirdPartySDK.framework
-Headers
MobileAPI.h
MyThirdPartySDK.h
-Modules
module.modulemap
MyThirdPartySDK
-www
cordova-plugin-my-custom-stuff.js
package.json
plugin.xml
plugin.xml ios 部分看起来像:
<platform name="ios">
<config-file parent="/*" target="config.xml">
<feature name="MyCustomStuff">
<param name="ios-package" value="MyCustomStuff"/>
</feature>
</config-file>
<source-file src="src/ios/MyCustomStuff.m"/>
<source-file src="src/ios/MyCustomStuffSDK.framework" framework="true"/>
<header-file src="src/ios/MyCustomStuffSDK.framework/Headers/MobileAPI.h" target-dir="MyCustomStuff" />
</platform>
我正在寻找驻留在 plugin.xml 配置或其他一些 ionic /cordovaproject 配置中的解决方案。我想避免编辑 xCode 项目,因为这都是由 ionic/cordova 命令行生成的 "automagically"。
终于想通了。
<platform name="ios">
<config-file parent="/*" target="config.xml">
<feature name="MyCustomPlugin">
<param name="ios-package" value="MyCustomPlugin"/>
</feature>
</config-file>
<source-file src="src/ios/MyCustomPlugin.m"/>
<source-file src="src/ios/MyCustomPlugin.framework" target-dir="lib" framework="true" />
<framework src="src/ios/MyCustomPlugin.framework" embed="true" custom="true" />
<header-file src="src/ios/MyCustomPlugin.framework/Headers/MobileAPI.h" target-dir="MyCustomPlugin" />
</platform>
我有一个使用插件的 Ionic5 (cli 6.3.0)/Cordova 9.0.3 (cordova-lib@9.0.2) 项目。
我正在尝试为第 3 方框架创建自定义插件。
我知道插件的框架是正确的,因为我是用 Plugman 创建的,在添加框架之前我可以 build/run 并从 "coolMethod" 得到 运行 的反馈=43=] 文件.
即使在添加框架之后,我也可以通过 ionic cordova plugin add ./packages/cordova-plugin-my-custom-stuff
我可以 Ionic/Cordova 使用 ionic cordova build ios
但是当我尝试从 Ionic 命令行 ionic cordova run ios
或自动生成的 xCode 项目 运行 iOS 模拟器时,我得到
dyld: Library not loaded: @rpath/MyThirdPartySDK.framework/MyThirdPartySDK
Referenced from: /Users/myUser/Library/Developer/CoreSimulator/Devices/C9E28EFF-B017-4F5E-
BA89-5200AE5D64EA/data/Containers/Bundle/Application/775C8394-B014-4B01-89CA-
1D462FD54F4A/MyName Mobile-UAT.app/MyName Mobile-UAT
Reason: image not found
项目的结构(为清楚起见进行了压缩)如下所示:
MyProject
-node_modules
-packages
-cordova-plugin-my-custom-stuff
-src
-ios
MyCustomStuff.m
-MyThirdPartySDK.framework
-Headers
MobileAPI.h
MyThirdPartySDK.h
-Modules
module.modulemap
MyThirdPartySDK
-www
cordova-plugin-my-custom-stuff.js
package.json
plugin.xml
plugin.xml ios 部分看起来像:
<platform name="ios">
<config-file parent="/*" target="config.xml">
<feature name="MyCustomStuff">
<param name="ios-package" value="MyCustomStuff"/>
</feature>
</config-file>
<source-file src="src/ios/MyCustomStuff.m"/>
<source-file src="src/ios/MyCustomStuffSDK.framework" framework="true"/>
<header-file src="src/ios/MyCustomStuffSDK.framework/Headers/MobileAPI.h" target-dir="MyCustomStuff" />
</platform>
我正在寻找驻留在 plugin.xml 配置或其他一些 ionic /cordovaproject 配置中的解决方案。我想避免编辑 xCode 项目,因为这都是由 ionic/cordova 命令行生成的 "automagically"。
终于想通了。
<platform name="ios">
<config-file parent="/*" target="config.xml">
<feature name="MyCustomPlugin">
<param name="ios-package" value="MyCustomPlugin"/>
</feature>
</config-file>
<source-file src="src/ios/MyCustomPlugin.m"/>
<source-file src="src/ios/MyCustomPlugin.framework" target-dir="lib" framework="true" />
<framework src="src/ios/MyCustomPlugin.framework" embed="true" custom="true" />
<header-file src="src/ios/MyCustomPlugin.framework/Headers/MobileAPI.h" target-dir="MyCustomPlugin" />
</platform>