Install Cordova plugin without package.json file on it - android

I'm trying to install a Cordova Plugin with Cordova CLI 7.
This plugin does not have a package.json file on it, so it throws an error when adding it to my project.
I've tried converting the config.xml file using plugman. And it works fine for Android but it doesn't for iOS. I feel like I'm missing some configuration from the config.xml in my package.json file.
Is there a way to safely convert the config.xml in a package.json file? or a way to install it using the config.xml file?
Thanks

Yes, since Cordova 7, the installation of platforms and plugins are by default performed using cordova-fetch which in turn uses npm install to add/remove modules. Therefore a package.json is required by default. But you should be able to add plugins lacking a package.json file by using the nofetch parameter, which forces Cordova to use the old method instead, please note that this parameter has been removed in cordova 8.0.0:
cordova plugin add cordova-plugin-camera --nofetch

For me when adding a custom plugin like so
cordova plugin add .\custom-plugins\my-plugin --nofetch
This does not work on MAC for me for some reason.
I resort to building it all for Android then copy over all the files, except node_modules and platforms, then do a 'cordova build ios' it seems to build fine with the custom plugins included. Not the best way i know, but once the plugin is added i can move on and continue. If you get it to work please share.

--nofetch option is removed in Cordova 8.0.0: https://issues.apache.org/jira/browse/CB-13055
If you have already installed Cordova 8.x.x then you can downgrade it to version 7.1.0 and then use the --nofetch option.
Run the following command to downgrade Cordova to 7.1.0:
npm install -g cordova#7.1.0
If the above command doesn't work, then try uninstalling cordova at first and then install cordova version 7.1.0:
npm uninstall -g cordova
npm install -g cordova#7.1.0
Then, check the Cordova version:
cordova --version

Related

Unable to add android project - ionic( Error - com.couchbase.lite.phonegap)

I am trying to add android platform to my existing ionic project. I am getting the below error.
Failed to restore plugin com.couchbase.lite.phonegap from config.xml. You might need to try adding it again.
Error:
Error: npm: Command failed with exit code 1 Error output:
I guess you tried on Android >= 7 which is needed for the couchbaselite plugin.
so you can downgrade to 6 :
ionic cordova platform rm android
ionic cordova platform add android#6
But if you need a recent android, you have to apply this Fixes : https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin/pull/110
remove manually node-modules and package-lock.json (imp*)
npm cache clean --force
finally run npm install
ionic cordova platform add android
I suggest you to remove the plugin and it's folder:
ionic cordova plugin remove couchbase-lite-phonegap-plugin
rm -rf plugins/com.couchbase.lite.phonegap/
Also, remove any line in package.json using the wrong folder name of com.couchbase.lite.phonegap, if you find any.
Then add your android platform as usual, then add the plugin back.
ionic cordova platform add android
ionic cordova plugin add couchbase-lite-phonegap-plugin
And if you still get any error, repeat the operation using the cordova --verbose directly, without ionic command. Example:
cordova plugin add couchbase-lite-phonegap-plugin --verbose
That command above should tell you exactly what went wrong.

Cordova failed to install 'cordova-plugin-whitelist': Error: ENOENT: no such file or directory AndroidManifest.xml

I have Cordova 8.0.0 on OSx 10.13.2 with Node v8.5.0 and npm v5.5.1.
After adding plugin cordova-plugin-ibeacon, when I do a cordova platform add android, I am getting following error:
failed to install 'cordova-plugin-whitelist': Error: ENOENT: no such file or directory AndroidManifest.xml
Screenshot:
You are using cordova-android#~7.0.0
I have faced same issues with recent pull of cordova-android repo with Cordova 8.0.0
Downgrade cordova-android to 6.4.0 as follows:
cordova platform remove android
cordova platform add android#6.4.0
This is a bit late. But sharing some personal observations when I encountered similar issues.
The build process fails if there is an old plugin that is not updated to work with the platform#7.0.0. At least this is the case for me. After installing this incompatible plugin, it would mess up the files in platform. After which trying to salvage the project by removing the plugin would also fail, because the files would have been put in the wrong directories when installing. You would have to remove the platform "cordova platform rm " followed by the misbehaving plugin "cordova plugin rm " and re-add back your platform before the the build can fixed.
Why android#6.30 and android#6.4.0 may work is because it is probably using the older platform project directory layout, where it appeared to use the top level /platforms/android directory for 'res' and 'libs' folder.
From android#7.0.0 onward, I notice it added the 'app' subdirectory, and your 'config.xml' and 'res' are expected at '/platforms/android/app/src/main/res/xml/config.xml' and not '/platforms/android/res/xml/config.xml'.
Older plugin may have installation/removal scripts that copy the files to the wrong places.
The only 2 ways to fix this problem is to update the plugin or downgrade the platform as suggested by Bharat Biswal.
If anyone has a more definite answer, that would be great.
You are using cordova 7.0.0 or cordova 8.0.0,
similar issue is observed with IONIC as well
You will find this issues with most of the plugins
such as admobpro, admob, itablet, whitelist etc.
Better for now roll back to previous cordova version i.e 6.3.0 or 6.4.0
If you see mentioned issues with any of plugins try this.
cordova platform remove android
cordova platform add android#6.3.0
OR
cordova platform remove android
cordova platform add android#6.4.0

ionic unable to add SocialSharing-PhoneGap-Plugin

I am trying to use SocialSharing-PhoneGap-Plugin in my first app development,
https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin#web-share-api
I have tried following command :
cordova plugin add SocialSharing-PhoneGap-Plugin
cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git
but It gives me same error , Anyone know what the problem is?
Some plugins can install in specific versions of cordova.
so please downgrade your cordova version and try to install that plugin again.
if your cordova version is 7+, downgrade to 6.5.0
npm install -g cordova#6.5.0
The plugin name is case sensitive, so the right one is:
cordova plugin rm cordova-plugin-x-socialsharing

cordova plugin rm cordova-plugin-whitelist does not change config.xml so it will be readded upon build

When I run
cordova plugin rm cordova-plugin-whitelist
and then run
cordova build android
I get the following message:
Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project
Fetching plugin "cordova-plugin-whitelist#1" via npm
Installing "cordova-plugin-whitelist" for android
This plugin is only applicable for versions of cordova-android greater
than 4.0. If you have a previous platform version, you do not need
this plugin since the whitelist will be built in.
and then the build proceeds.
So cordova plugin rm is not removing the plugin as I never installed it, as it should?
edit
Removing this plugin will make the webview blank. I expected it to accept any url, but it rejected everything.
I'm not sure what your question is here. In order to remove the plugin from the config.xml file, you'll need to add the --save flag to the cordova plugin rm call (reference):
cordova plugin rm <plugin-id> --save
Without the --save flag, the plugin is removed from the app, but not from the config.xml file.
So when you next call cordova build or cordova prepare, the script will look at your config.xml file and add any plugins that are specified there but not installed. So the plugin will be added back.

Cordova 3.4: How to Manually Install a Plugin

I would like to manually install this plugin into my Android application, which is built on Cordova 3.4. The plugin is compatible with Cordova up to v3.1. The plugin checks to see if geolocation via GPS is enabled on a device.
I've attempted referencing the plugin in res/xml/config.xml, however this reference is removed each time I run cordova build android. The result is that when I run the program I get a Class not found error.
Any thoughts on this particular scenario or just how to manually install a Cordova 3.4 plugin would be greatly appreciated.
Many Thanks!
Add Plugin Features
If you use a platform-specific workflow, you use a lower-level Plugman command-line interface, separately for each targeted platform.
Installing Plugman
To install plugman, you must have node installed on your machine. Then you can run the following command from anywhere in your environment to install plugman globally, so that it is available from any directory: $ npm install -g plugman
Adding a Plugin
Once you have installed Plugman and have created a Cordova project, you can start adding plugins to the platform:
Check this link : Plugman to manage Plugin
Edited : Plugman to Manage Plugins (3.4.0)

Categories

Resources