I made a cordova plugin for Android applications, but unlike other plugins, this one only uses an Application (App.java) and not a CordovaPlugin class.
When I try to install it for the first time using cordova plugin add, it works fine. When I try to remove it using cordova plugin rm, it doesn't remove the folder from node_modules and keeps the plugin dependency name in the package.json. Besides, it removes some code from the manifest that belongs to another plugin (I've seen this is a consecuence of the edit-file in the plugin.xml, I need to add the Application name to the manifest) and if I try to install it again I will get an error (because it's still holding the node_modules dependency) unless I update the version of the plugin.
Here's my plugin.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="com.test.plugin.applicationTest" version="1.0.0" platform = "Android">
<name>codova-app-plugin</name>
<description>Test</description>
<author>test</author>
<license>Apache 2.0</license>
<keywords>cordova, application</keywords>
<platform name="android">
<config-file parent="/*" target="res/xml/config.xml">
<feature name="applicationTest">
<param name="android-package" value="com.test.plugin.applicationTest" />
</feature>
</config-file>
<source-file src="src/android/App.java" target-dir="src/com/test/plugin/applicationTest" />
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</config-file>
<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
<application android:name="com.test.plugin.applicationTest.App"/>
</edit-config>
</platform>
</plugin>
Why it isn't removing the node_modules? and what can I do to avoid the deletion of the AndroidManifest tags ?
Edit:
If I remove the edit-config and instead use a hook, I won't delete the AndroidManifest tags, but they won't get executed or throw EACCESS error. Besides, it keeps the node_modules dependencies.
<hook type="after_plugin_install" src="scripts/nameManifest.js" /> -- won't execcute
<hook type="before_plugin_uninstall" src="scripts/uninstallPackage.sh" /> -- EACCESS error
For now, the best I can do is to remove that edit-config and create hooks for the edition of the application name and the execution of npm uninstall
Related
I am developing a cordova plugin and I want to publish now. However, I need to invoke some third party plugins in my plugin, such as cordova-plugin-camera and cordova-plugin-googlemaps. Currently I'm merging everything and given source path in plugin.xml manually, which is a poor code management. I want to know if I can add the dependencies in plugin.xml and free my work.
Actually, I'm helping my friends to solve his problem. Read this Doc of plugin.xml. And specifically:
The <dependency> tag allows you to specify other plugins on which
the current plugin depends. The plugins are referenced by their unique
npm ids or by github url.
Therefore, what you should do is simple:
<dependency id="cordova-plugin-camera" version="^1.1.1" />
but be careful when you dealing with feature and permission in manifest.xml, if you still have those issues after addinig those dependencies, you need add them in plugin.xml as well:
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</config-file>
Hopefully it will solve your problem.
Some <uses-permission> entries are added automatically to AndroidManifest.xml, based on cordova plugins that you add. However, I need the <uses-permission android:name="android.permission.INTERNET" /> permission, which isn't added automatically.
I can add that directly to AndroidManifest.xml, but it will get overwritten the next time I run cordova build, and I don't want to have to keep re-adding it...
I'm sure there's a "Cordova" way of specifying permissions (in config.xml, or elsewhere), but I'm not seeing it in their documentation anywhere...
So, what is the "Cordova way" of specifying user permissions?
As I know AndroidManifest.xml will not be generated every time when you run cordova build. When you add/remove a plugin it will be modified accordingly. But if you add your own permissions it will not be removed(Unless there is a conflict).
Since the permissions are Android (platform) specific, in your case you have to add it into the AndroidManifest.xml file only.
Even in plugin.xml of any plugin they add permission as shown :
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET"/>
</config-file>
</platform>
Which says add uses-permission line to AndroidManifest.xml file at the installation time of plugin. But you cant mention this in config.xml file.
Also don't forget to put this attribute in the root widget element present in the config.xml file,located in the root folder of the app, as #hiddentao said in a comment.
config.xml
<widget
xmlns:android="http://schemas.android.com/apk/res/android"
...>
Cordova (version 8) has built in functionality for this.
I was able to add the required 'uses-permission' line to AndroidManifest.xml using the following in config.xml:
<platform name="android">
...
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/uses-permission" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
</edit-config>
...
</platform>
One can add this plugin (Git).
It makes you capable of defining platform-specific configurations (permissions too) under config.xml file in the following way:
<platform name="android">
<custom-config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.INTERNET" />
<!--<uses-permission android:name="android.permission.NETWORK_ACCESS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />-->
</custom-config-file>
</platform>
Also don't forget to put this attribute in the root widget element as #hiddentao said in a comment.
xmlns:android="http://schemas.android.com/apk/res/android"
Manually add under config-file tag
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET"/>
</config-file>
When trying to add https://github.com/hygieiasoft/cordova-plugin-uid to visual studio via the config.xml designer, it "recognises" there is a plugin, but ends with blank fields for all the properties (version, plugin id, etc.), even if you wait for minutes (most others find all properties in seconds). If you then try and add it, it simply crashes VS and restarts. I have tried with plugins that do not support ALL platforms, with success, but not this one.
Has anyone had any luck adding this to VS or have any ideas. Since the project is cross platform, I would prefer to use the recommended way, even though this is android only, but am open to suggestions. Ultimately, I am only looking for IMEI.
A user suggested using Telerik App Studio, as the process is simpler to copy the plugin into the www folder, but apart from the cost, I would, as noted, prefer keep within the confines of a somewhat recommended way that will continue working when upgrading to VS 2015 and beyond.
Do the following steps -
1) Download the plugin on your windows desktop. Unzip the downloaded file.
2) Add facebookconnect.xml file to the folder where plugin.xml is present. Add your app id and application name. Place the below tags inside resources tag -
<string name="fb_app_id"></string>
<string name="fb_app_name"></string>
3) Modify the plugin.xml file to include facebookconnect.xml file. It should look like below -
<config-file target="res/xml/config.xml" parent="/*">
<feature name="FacebookConnectPlugin">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
<access origin="https://m.facebook.com" />
<access origin="https://graph.facebook.com" />
<access origin="https://api.facebook.com" />
<access origin="https://*.fbcdn.net" />
<access origin="https://*.akamaihd.net" />
</config-file>
<source-file src="platforms/android/res/values/facebookconnect.xml" target-dir="res/values" />
<config-file target="AndroidManifest.xml" parent="application">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/fb_app_id"/>
<activity android:label="#string/fb_app_name" android:name="com.facebook.LoginActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar"></activity>
</config-file>
<framework src="platforms/android/FacebookLib" custom="true" />
<!-- cordova plugin src files -->
<source-file src="platforms/android/src/org/apache/cordova/facebook/ConnectPlugin.java" target-dir="src/org/apache/cordova/facebook" />
</platform>
4) Now Go into Visual Studio and add the plugin from the directory where plugin files are present. It will take some time to be added.
Hope this helps you fix the problem.
I'm writing a Plugman-compatible Cordova plugin. Installing it via Plugman, I've confirmed it installs correctly and runs normally:
plugman --platform android --project /platforms/android --plugin my/plugin.path
But if I use:
cordova build/cordova run android
it doesn't work even with plugin installed. This is because Plugman only installs my plugin js file to the /platforms/android/assets/www folder and not the base /www folder, so when I build, the /www folder without the plugin gets copied to /platforms/android/assets/www.
Is there an option or something in plugin.xml I should be specifying to install the plugin to the project root www folder?
When using Cordova CLI, you shouldn't install plugins using plugman. Cordova CLI does use plugman under the covers, but what you want to use is cordova plugins add http://... or cordova plugins add /path/to/plugin.xml.
You didn't specify which version of Cordova you are using, but here's some examples of adding plugins that are core functionality: http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface
It should put the js files in platforms/android/assets/www/plugins/com.plugin-name/www and the java files in platforms/android/src/com/plugin-name/
You can specify this in the plugin.xml file like this (this is an example from a plugin that I upgraded to https://github.com/aharris88/phonegap-sms-plugin3.0 ()):
<js-module src="www/sms.js" name="Sms">
<clobbers target="window.sms" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Sms">
<param name="android-package" value="com.adamwadeharris.sms.Sms"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.SEND_SMS" />
</config-file>
<source-file src="src/android/Sms.java" target-dir="src/com/adamwadeharris/sms" />
</platform>
I'm writting an android and iphone app using phonegap 3.0.
So far I have been only compiling the apps remotely using phonegap build.
Now I'm trying to add the geolocation plugin to my app, and in iphone was easy, since I only had to modify the config.xml file.
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
So far so good, the problem was that when adding geolocation to android, the documentation indicates that I have set the following configuration:
(in app/res/xml/config.xml)
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.GeoBroker" />
</feature>
(in app/AndroidManifest.xml)
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
But I don't have an AndroidManifest.xml file. I could generate the complete android app using:
cordoba platform add android
But I'm not sure if this is what I should do.
Is is what I should be doing? or there is a way to add geolocation without generating the entire android project?
I am a bit confused because you say you are using phonegap 3.0 and you also mention phonegap-build (highest is 2.9). If you are in fact using phonegap-build, the only thing you need is in your config.xml:
<feature name="http://api.phonegap.com/1.0/geolocation"/>
I had the same problem. My geolocation worked on IOS but not on Android. So I Added to config.xml
<feature name="http://api.phonegap.com/1.0/geolocation"/>
As explained by Dom.This was not sufficient. I wanted to share what I did step by step because I lost about 18h of dev time looking for the solution.
This however did not reslove the problem. So I added the plugin using my IDE.
This added the following to the config:
<plugin name="cordova-plugin-geolocation" version="2.2.0" />
I then went inside the plugin.xml under the plugin directorty.
And looked if the following was added.
<!-- android -->
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</config-file>
...
It was, so I rebooted the device. (on the Ionic forum they say, it might help)
When reinstalling the app I checked for the permission. And it was added. So for the bad Q of the last pic but I took a pic with my cam for it. Hope this helps