How can I get a plugin to work by installing it NOT from the repository.
Each plugin I try to install using phonegap plugin add <<git repository>> always results in different errors, because windows + npm just doesn't want to work for me...
This is the plugin I need: https://github.com/VersoSolutions/CordovaClipboard
My steps:
Download Git repository
Run phonegap plugin add <<downloaded and extracted directory>>
Remove and add android platform (yes it says that it installed the plugin)
Start Phonegap Developer app
But cordova.plugins.clipboard is still undefined. Do I have to put the clipboard.js file somewhere or reference it? If so, which version?
The one in the clipboard project or the one phonegap automatically creates within the platform/android directory (it puts a "define" around it). I actually tried both, but the object was still undefined.
The clipboard plugin does not have a package.json present which is why you are getting the error. You can either add a package.json file to the plugin or you can install it with the --nofetch flag:
cordova/phonegap plugin add https://github.com/VersoSolutions/CordovaClipboard.git --nofetch
Since cordova 7.0.0 npm install is run by default when adding a new plugin which causes an error if no package.json is present. You can find the release notes for cordova 7.0.0 here.
Related
Long story short, I've tried all sorts of solutions SO and other sites have proposed, and I'm certain none of them handle my scenario. I'm using Cordova to build my apps. I recently reinstalled Cordova, and apps stopped building.
Yes, I've installed and included gradle in my path (I'm on Windows)
I've verified and gradle is installed (gradle -v) from command prompt
When I open the project directly from Android Studio, it finds gradle and builds successfully
When I use cordova to run it from the cmd, I get the above error
Funny enough, when I delete downloaded files from C:\user\.gradle as some SO and GitHub solutions suggest, it downloads gradle, and after completing the download, still tells me gradle couldn't be foound
I've upgraded Node, NPM and Cordova to their latest versions. If it's of any help, I'm building on Ionic and both Ionic and Angular have been equally upgraded to their latest versions. Ionic serve and every other related command works. Here's the command that triggers the error:
ionic cordova run android
You should ensure the path of the gradle installation is exactly the same path you are setting in your environment/path variable.
That solved it for me
I'm trying to add additional Phonegap plugins (namely, the File plugin) to an existing android application that uses Phonegap.
I've tried navigating to my project directory (in my workspace) and then run the command
cordova plugin add https://theurlwhichworks.org/
It says the plugin is installing, and when I go to look in my workspace on my computer, there is a folder titled plugins, and inside, a directory called
org.apache.cordova.file
which means that the plugin (apparently) downloaded correctly, but doesn't seem to have been added to my project.
Is there any way to manually add this plugin (or others) to my android project directly? I build+run my application to an attached device from eclipse, because anytime I try to use the CLI with regard to cordova/phonegap I always seem to be doing something wrong, or the result is not at all what I expected.
Hopefully it is possible to add these plugins manually. I appreciate any suggestions
It is possible to add plugins manually, and that is how we did it in the old days before the Cordova/Phonegap CLI or PlugMan
options
A. use PlugMan directly
npm install -g plugman
check out the plugman documentation. Outside of a Cordova project, plugman is your best bet for a clean automated install
B. manually
add the .java files to the android project src/ directory
remember their path has to match their namespace
dump the plugin js file somewhere in assets/www/*
add a feature tag to platform config.xml
It has been a long time since I added a plugin manually, and the cordova plugin spec has gone through major changes multiple times since then. You may need to manually include the plugin js implementation (eg via script tags in index.html)
I would highly recommend you use PlugMan, or at least try before the manual install.
Seems you're using eclipse.
A cordova 3.x project looks like this :
/www
/plugins
/platforms
/platforms/android
/platforms/android/assets/www
...
When you run cordova plugin add https://theurlwhichworks.org/ the plugin is added only in the /plugins folder but not in your platform folder.
In your eclipse project you only see /platforms/android folder.
To actually add the plugin to the android platform, you have to build the platform :
cordova build android
or at least prepare the platform (same as build but does not try to compile):
cordova prepare android
But be aware that when you either build or prepare, the content of the platform/android/assets/www folder will be replaced with the content of the root www folder.
So if you've been modifying directly the assets/www folder in eclipse, DO NOT FORGET TO SAVE IT BEFORE YOU BUILD OR PREPARE!!!
Every time plugins start acting funny for me I usually remove and re-add the platform and everything usually sorts itself out. The commands for Android for example,
cordova platform remove android
cordova platform add android
If your plugin list has what you expect, re-adding the platform re-downloads all the plugins.
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 ;)
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 cordova#3.3.0-rc.1
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.
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.
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.
Check you index.html file has the correct <script></script> lines.
I had an issue when creating a new project via CLI. The index.html file referenced phonegap.js instead of cordova.js
I am trying to check for an established network connection through the phonegap/cordova API, but alas, it is not working.
I added the plugin as explained on the cordova documentation, and phonegap local plugin list gives [phonegap] org.apache.cordova.network-information.
However, simply calling
document.addEventListener("deviceready", function () {
alert(Object.keys(navigator.connection));
}, false);
results on my phone (Android 4.0.4) always returning 0 and running on an emulator with Android 4.4.2 logs into LogCat that navigator.connection is undefined. In fact, on both machines alert(Object.keys(navigator)); never shows the connection key.
Any solution?
Phonegap with Cordova 3.3.0
When you install the plugin it copies files to www/plugins and updates android.json
then when you build the project, the build copies the java to platforms/android/src/... and the js files to platforms\android\assets\www\plugins (and does any customisation defined in plugin.xml)
At multiple occasions I saw android.json not correctly updated and javascript files not copied. Removing and re-installing plugins solved the problem for me.
If you did not perform manual customisations to the platforms/android folder, I think the easiest way to clean your project would be to empty the /plugins folder and the platforms folder and then re-install all the plugins you need.
I had the same issue and found I had to run "cordova build" and then the status was returned correctly.
BEWARE
When I run cordova build, it appears to take everything in my ~/app/www directory and overried everything in app/platforms/android/assets/www/
My "install process" is as follows:
cordova create app com.app "App"
cd app
cordova platform add android
cordova plugin add org.apache.cordova.network-information
cordova plugin add org.apache.cordova.camera
cordova plugin add org.apache.cordova.geolocation
cordova build
I can then do code changes in app/www and when happy, 'deploy' it using 'cordova build' (which seems to always copy the files to app/platforms/android/assets/www/.
If I add another plugin using: (for example)
cordova plugin add org.apache.cordova.file
then I need to run
cordova build
to have it work.
I hope this helps
(I am using cordova 3.3.1-0.1.2 )
I have cordova 3.3 installed (in 3.2, have the same error) and when i want to add or remove a plugin the system show this error:
>>cordova plugin add org.apache.cordova.network-information
Fetching plugin from "org.apache.cordova.network-information"...
Starting installation of "org.apache.cordova.network-information" for android
/usr/local/lib/node_modules/cordova/node_modules/q/q.js:126
throw e;
^
SyntaxError: Unexpected token
I check the path and is correct:
echo $PATH
/usr/local/bin:/Users/manuelcm/Documents/sdk_android/platform-tools:
/Users/manuelcm/Documents/sdk_android/tools:/usr/local/apache-ant/bin:
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
In my first installation i install the plugins and the plugins directories appear in /plugins/ but after build in iOS only de device plugin appear in /platforms/ios/www/plugins this is the reason that I want to reinstall the plugins.
Anyone know why this is happening and how to resolve it?
Finally I solved the problem, first I created the project in local disk.
The problem persisted, then I created the project with uppercase in the first letter of project name, and all works fine. Yes, it seems incredible, but this was the solution.
I had the same problem after I upgraded to cordova 3.3.0, when I tried 'cordova rm' the plugins (after I removed android.json from the plugins folder).
But the problem resolved for me when after I ran 'cordova add' all the plugins.
So I suppose you could try 'cordova plugin list' to see if it knows which plugin is added.
if it does know then try removing 'plugins/android.json' then add each of the plugin back in follow by 'cordova build'.
Also if you have angularjs, you might want to remove the /docs for it as it could also produce the error
And you might want to check your /platform/android/project.properties is it using a target that you are expecting? (e.g. android-16 but you don't have it set up?)
I had similar issue while installing org.apache.cordova.dialogs plugin. I deleted content under www folder and executed the same command. It worked. Under www folder I had my project which uses Angular. Not sure if angular has any conflict with this.