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>
Related
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
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.
I am writing a Cordova plugin for Android, and it is not registering a JavaScript object to window and I would like to know why.
In the plugin's plugin.xml, I am using <js-module> to register the js object to window object:
<platform name="android">
<js-module src="www/Loading.js" name="loader">
<clobbers target="loader" />
</js-module>
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Loading">
<param name="android-package" value="org.apache.cordova.loader.Loading" />
<param name="onload" value="true" />
</feature>
</config-file>
...
</platform>
The plugin compiles, but when I do window.loader in Chrome debugger, it is undefined. I tried changing the value of target in <clobbers> to window.loader to no avail.
www/Loading.js file is exporting a JavaScript object using module.exports:
function Loading() {
...
}
module.exports = new Loading();
Any suggestions?
Resolved. This is a very specific case for my app. I am copying everything from the sandboxed environment to an internal path and booting the app from the internal path. Turns out the app was not copying the www/Loader.js 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 am working on an Android App with Phonegap Cordova-3.0.0 and when I call InAppBrowser I got MotionEvent mTouchMode = 4 error. And InAppBrowser function is not working. So how can I fix this? Do I need do some setting on AndroidManifest.xml or config.xml?
And I got this on my AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
And I got this on my config.xml
<plugins>
<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
</plugins>
In Phonegap Cordova-3.0.0 version, for the app to communicate closely with various device-level features, we need to add plugins that provide access to core Cordova APIs.
The cordova plugin add command requires you to specify the repository for the plugin code.
For example, In-app browser:
$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
we need run this in command line. Don't need worries about AndroidManifest.xml or config.xml files. After you run $ cordova build, it will auto write for you.
You could get more idea about it in doc.phonegap
Add following code in config.xml this works fine for mi.
<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
<access origin="*" browserOnly="true"/>
You have to mention the below code line in config.xml
<plugin name="InAppBrowser" value="CDVInAppBrowser" />
try to add this to your manifest, it helps me with a f*king plugin to work
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
try also not use 'plugin' tag in config.xml, but:
<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.InAppBrowser"/>
</feature>
it will help for future updates of phonegap
To open a link in browser inside the app without opening external browser
HTML
<input type="button" id="button1" value = "click here"
onclick="window.open('https://example.com','_blank','location=yes','closebuttoncaption = Return');">
Now go into your project folder and open Terminal or Command Prompt (Windows) and type the following command:
cordova plugin add cordova-plugin-inappbrowser --save
It will configure the required files and also add the plugin into your config.xml file.
Open your HTML page where you're trying to open the link, and put this JavaScript.
<script src="cordova.js"></script>
<script type = "text/javascript" charset = "utf-8">
function onLoad(){
document.addEventlistner("deviceready", OnDeviceReady, false);
}
function onDeviceReady(){
}
</script>