Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Library Resource to Cordova Project?

When writting a few cordova plugins, source/header files, iOS libraries and Android Jar from some SDK, resource files, can all be added to Cordova plugin.

When using google-play-services.jar, the library project contains some resource files, If the resources added, will generated R.java in app namespace, not the SDK namespace.

There is some workaround to add the library project (including jar and resource) into created Cordova project, but such workaround cannot be used if build Cordova app in cloud service like Intel XDK or PhoneGap Build.

Is it possible to add SDK resource and generate R.java in SDK namespace? If yes, how?

like image 749
Raymond Xie Avatar asked Sep 30 '14 13:09

Raymond Xie


People also ask

Which of the following command is used to add plugin in cordova app?

The cordova plugin add command requires you to specify the repository for the plugin code. Please note that when you follow the Web Project Dev workflow and use the CLI, the CLI will take care of adding the plugin code to the appropriate place for each platform.

How plugins are used in Apache Cordova?

A plugin is a package of injected code that allows the Cordova webview within which the app renders to communicate with the native platform on which it runs. Plugins provide access to device and platform functionality that is ordinarily unavailable to web-based apps.


1 Answers

It's a pity the questions is not answered yet.

Good news is, after struggled for weeks, I happen to learn the solution from another project: https://github.com/MobileChromeApps/google-play-services

A new feature is added to Cordova plugin.xml, to support android sub-project to be added to Cordova project. Here is the example from the project above,

<framework src="libs/google-play-services_lib" custom="true" />

For iOS, it's quite similar, add a framework like this:

<framework src="src/ios/MobFox.framework" custom="true"/>

Then cordova CLI will know how to add the whole folder to Cordova project, and add as sub project to eclipse project, and add framework to Xcode project file.

But, be aware !!

Though cordova CLI support this new feature, Intel XDK does not support it yet !!! At the time of writing this post (Nov 15, 2014), it still use cordova v3.3.

The result is:

If you write a plugin, and use the plugin "com.google.playservices" as a dependency,

  • When using cordova CLI, you plugin can be built without any problem.
  • If use Intel XDK, you plugin cannot be loaded.

Then, how to fix it for Intel XDK?

The answer is: specify the exact version number of the dependency in your plugin.xml, like this:

<dependency id="[email protected]"/>

Hope the above information is useful to someone who encountered the same problem.

Cheers.

like image 77
Raymond Xie Avatar answered Oct 16 '22 07:10

Raymond Xie