Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova 3.3.1-0.1.2 (Phonegap) plugins doesn't work

I have a cordova 3.3.1-0.1.2 test project for iOS, where I use the following plugins (cordova plugin ls):

[ 'com.phonegap.plugins.PushPlugin',
  'org.apache.cordova.console',
  'org.apache.cordova.device',
  'org.apache.cordova.splashscreen' ]

I've added the plugins like this cordova plugin add org.apache.cordova.device. In my git repo, I see, that it adds a bunch of files to the plugins/org.apache.cordova.device directory, creates a CDVDevice.h and a CDVDevice.m in my iOS plugin directory, updates the ios.json, updates the *.xcodeproj file and adds the plugins to my config.xml inside platforms/ios/test-app/config.xml:

<feature name="Device">
    <param name="ios-package" value="CDVDevice" />
</feature>

But when I try to access the device or window.device property inside JS, it tells me, that device is undefined. The weird thing is, that the pushPlugin is present:

document.addEventListener("deviceready", function () {
   console.log(device);
   console.log(window.device);
   console.log(window.plugins.pushNotification);
});

The window.plugins object only lists the pushNotification plugin as a property. It's weird, because they are all installed, and during the installation, cordova said, everything was ok.

I'm a little bit confused, about the outdated, and mixed-with-phonegap documentation, but that would be ok, if one of them would work. I also saw a plugin definition, inside a config.xml like this

<gap:plugin name="org.apache.cordova.device" />

Can someone explain me, what's the difference? Is the way (with feature) that I'm working outdated with cordova 3.3? When I try to use the <gap:plugin... format, my app crashes on startup.

So, please help me to fix this, and clear my mind ;)

like image 398
23tux Avatar asked Jan 27 '14 18:01

23tux


3 Answers

Unfortunately, none of the answers worked. Luckily, I found the solution in this mailing list:

http://mail-archives.apache.org/mod_mbox/cordova-dev/201312.mbox/%3CCABiQX1Vat5XvmKkWt=+viL9oXWnOiAz5ee95h8oJp0j4MU9pJQ@mail.gmail.com%3E

There they say, that this is a bug in cordova 3.3.1. In this versions, the plugins get copied into the .staging directory of the different platforms.

So, downgrading with npm to cordova 3.3.0 now worked (on Mac OS X):

sudo npm remove -g cordova
sudo npm view cordova versions
sudo npm install -g [email protected]

And also check, if cordova is maybe installed from phonegap too. If you only use cordova, and non of the phonegap features (like remote build), you can safely remove the phonegap package with

sudo npm remove -g phonegap

Update

The current version 3.4.0 works fine, and doesn't have this issues.

like image 78
23tux Avatar answered Oct 21 '22 19:10

23tux


plugin definition using gap:plugin is for configuring plugins for phonegap build (so you don't need it for local build).


As MBillau suggested, the plugins are added to the platform only after you run cordova prepare ios (or cordova build ios which launches prepare and then builds the project).

When you run prepare, javascript files of the plugin should be copied to the www/plugins/pluginfullname/www folder of the platforms/ios folder.

If the files are not there it may be an issue with the ios.json file being corrupted. In that case, sometimes uninstalling and then re-installing the plugin solves the problem. In some case you have to remove the ios.json file, and empty the plugins folder at the root of your project (and maybe allso the platforms folder) and re-install all the plugins.


If window.plugins object only lists the pushnotification plugin it is just because it is the only plugin installed in this object :

  • org.apache.cordova.console is in console and cordova.logger
  • org.apache.cordova.device is in window.device
  • org.apache.cordova.splashscreen is in navigator.splashscreen

To know javascript object name to use, you have to read the plugin's documentation or look at the js-module/clobbers property in the plugin.xml file of the plugin.

like image 33
QuickFix Avatar answered Oct 21 '22 20:10

QuickFix


From the root of your Cordova project, go into ./platforms/ios/

cd platforms/ios

In here there should be a ./build folder - this contains previously built packages which Cordova then uses for 'lazy loading' - i.e. so Cordova does not constantly have to fetch files from various locations, it stores them locally instead. However, I have found this to be problematic.

Delete this folder:

sudo rm -r build

When gone, rebuild your Cordova project:

cordova build

It should then recreate the build folder but more importantly, your plugins will be listed in config.xml.

like image 37
keldar Avatar answered Oct 21 '22 20:10

keldar