问题
The document says:
"There are two steps to including a plugin in your project:
Importing the native code using the config.xml
Referencing the JavaScript code for the plugin"
http://docs.build.phonegap.com/en_US/configuring_plugins.md.html#importing-native
And to reference you do this in your html file:
<script src="cordova.js"></script>
<script src="barcodescanner.js"></script> <-this
However, how do you know what to put in place of barcodescanner.js.
In fact i don't know about work flow of including plugins if i am using solely using phonegap build to build and test my app and not use anything local. I tried including plugin using cli. But that didn't update root config.xml
. So i manually put the code config.xml, as can be found https://build.phonegap.com/plugins/1163 . But on this page there was no mentioning of what to include in javascript file. do i use acceleration.js, device-motion.js
回答1:
if you want to include the bar code scanner with phonegap build you coulde do the following,
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.phonegap.example"
versionCode = "10"
version = "1.0.0" >
<!-- versionCode is optional and Android only -->
<name>PhoneGap Example</name>
<description>
An example for phonegap build docs.
</description>
<author href="https://build.phonegap.com" email="support@phonegap.com">
Hardeep Shoker
</author>
<!-- We'll include the Barcode plugin as an example -->
<gap:plugin name="com.phonegap.plugins.barcodescanner" />
<gap:plugin name="org.apache.cordova.camera"/>
<gap:plugin name="org.apache.cordova.device-motion"/>
<gap:plugin name="org.apache.cordova.device-orientation"/>
<gap:plugin name="org.apache.cordova.file-transfer"/>
<gap:plugin name="org.apache.cordova.geolocation"/>
<gap:plugin name="org.apache.cordova.dialogs"/>
<gap:plugin name="org.apache.cordova.vibration"/>
</widget>
This is an example config.xml file to include in the same directory as your homepage. In the javascript file you don't include any scripts for plugins(make sure
<script src="cordova.js"></script>
is included). Just call the plugin methods and build will handle the rest for you.For example I have included the vibration plugin above. If I wanted my phone to vibrate I would simply call a function like this,
function test(){
navigator.notification.vibrate(1000);
}
There is no need for anything like,
<script src="barcodescanner.js"></script>
Just make sure the plugin is referenced in the config.xml file and everything should be ok
来源:https://stackoverflow.com/questions/27318653/phonegap-build-how-do-you-add-plugins-to-app