如何在plugin.xml中添加同名但不同文件夹的资源?
Posted
技术标签:
【中文标题】如何在plugin.xml中添加同名但不同文件夹的资源?【英文标题】:How to add Resources with the same name but different folders in plugin.xml? 【发布时间】:2014-11-30 16:28:54 【问题描述】:我有一个 ios Objective-c 组件,应该包含在 PhoneGap/Cordova 插件中。
这是我的 plugin.xml 文件中的一部分:
<platform name="ios">
...
<resource-file src="src/ios/TGCameraViewController/View/Base.lproj/TGCameraAuthorizationViewController.xib" target-dir="TGCameraViewController/View/Base.lproj" />
<resource-file src="src/ios/TGCameraViewController/View/Base.lproj/TGCameraViewController.xib" target-dir="TGCameraViewController/View/Base.lproj" />
<resource-file src="src/ios/TGCameraViewController/View/Base.lproj/TGPhotoViewController.xib" target-dir="TGCameraViewController/View/Base.lproj" />
<resource-file src="src/ios/TGCameraViewController/View/de.lproj/TGCameraAuthorizationViewController.strings" target-dir="TGCameraViewController/View/de.lproj" />
<resource-file src="src/ios/TGCameraViewController/View/de.lproj/TGCameraViewController.strings" target-dir="TGCameraViewController/View/de.lproj" />
<resource-file src="src/ios/TGCameraViewController/View/de.lproj/TGPhotoViewController.strings" target-dir="TGCameraViewController/View/de.lproj" />
<resource-file src="src/ios/TGCameraViewController/View/pt-BR.lproj/TGCameraAuthorizationViewController.strings" target-dir="TGCameraViewController/View/pt-BR.lproj" />
<resource-file src="src/ios/TGCameraViewController/View/pt-BR.lproj/TGCameraViewController.strings" target-dir="TGCameraViewController/View/pt-BR.lproj" />
<resource-file src="src/ios/TGCameraViewController/View/pt-BR.lproj/TGPhotoViewController.strings" target-dir="TGCameraViewController/View/pt-BR.lproj" />
</platform>
当我尝试将插件添加到我的应用程序时,我收到以下错误:
Failed to install 'org.test.cordova.TestPlugin':Error: Uh oh!
target destination "/Users/mg/Documents/iOS/hello/platforms/ios/HelloWorld/Resources/TGCameraAuthorizationViewController.strings" already exists
at module.exports.resource-file.install (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/ios.js:128:48)
at Object.ActionStack.process (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/util/action-stack.js:72:25)
at handleInstall (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:591:20)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:340:28
at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:749:13)
at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:509:49
at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
Error: Uh oh!
target destination "/Users/mg/Documents/iOS/hello/platforms/ios/HelloWorld/Resources/TGCameraAuthorizationViewController.strings" already exists
at module.exports.resource-file.install (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/platforms/ios.js:128:48)
at Object.ActionStack.process (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/util/action-stack.js:72:25)
at handleInstall (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:591:20)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:340:28
at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:749:13)
at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:509:49
at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
我尝试使用:
<framework src="src/ios/TGCameraViewController" custom="true" />
这样我可以包含整个文件夹,但是当我想创建 #import "SomeClass.h" 时却找不到文件。
【问题讨论】:
【参考方案1】:根据插件规范http://cordova.apache.org/docs/en/edge/plugin_ref_spec.md.html#Plugin%20Specification
resource-file 元素不支持任何目标属性。 target 属性适用于 android,不适用于 iOS。
解决方案很简单,删除您的 plugin.xml 中的内容(以上代码),然后将 <resource-file src="src/ios/TGCameraViewController"/>
保留在 plugin.xml 中并尝试构建。
【讨论】:
是否可以在 IOS 资源文件夹中创建新文件夹? @yaswanthsvist以上是关于如何在plugin.xml中添加同名但不同文件夹的资源?的主要内容,如果未能解决你的问题,请参考以下文章
我想在我的映射数组中添加一个新的 segmentId(同名),但 elementId 不同但方法相同