我们知道Cordova HTML5应用具有夸平台的特性,同一时候也具有訪问本地一些资源的能力。在今天的这篇文章中。我们将介绍一下怎样创建并执行一个Cordova HTML5的应用到我们的Ubuntu手机中。本文的英文原文在“http://developer.ubuntu.com/en/apps/html-5/guides/cordova-guide/”。
以下以15.04 framework为例:
$sudo click chroot -aarmhf -f ubuntu-sdk-15.04 create
等安装完以后,我们就能够进行下一步的动作。开发人员假设想为14.10的目标进行编译,也能够使用相同的方法来安装14.10的armhf chroot。
$rm -rf ~/.cordova $rm -rf ~/.cache
$ sudo apt-add-repository ppa:cordova-ubuntu/ppa; sudo apt-get update $ sudo apt-get install cordova-cli
在例如以下的命令中,假设没有指定详细的架构,14.10架构将会被採用。
$cordova create myapp myapp.mycompany "My App" $cd myapp $cordova platform add ubuntu $vi config.xml
<icon src="www/img/logo.png" />
<author email="myid@ubuntu.com" />
<?xml version='1.0' encoding='utf-8'?>
<widget id="myapp.mycompany" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>My App</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="myname@mycompany.com" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" version="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<icon src="www/img/logo.png" />
</widget>
以下我们来详细描写叙述怎么进行编译。
$ cordova build --device
在第一次编译时,可能须要我们去安装一些额外的库才干够进行编译。
它会提演示样例如以下所看到的的错误信息:
List of devices attached 750ABLLH4897 device Target Device: 750ABLLH4897 Building Phone Application... Error: missing dependency inside armhf chroot run: sudo click chroot -a armhf -f ubuntu-sdk-14.10 install cmake libicu-dev:armhf pkg-config qtbase5-dev:armhf qtchooser qtdeclarative5-dev:armhf qtfeedback5-dev:armhf qtlocation5-dev:armhf qtmultimedia5-dev:armhf qtpim5-dev:armhf libqt5sensors5-dev:armhf qtsystems5-dev:armhf
$sudo click chroot -a armhf -f ubuntu-sdk-14.10 install cmake libicu-dev:armhf pkg-config qtbase5-dev:armhf qtchooser qtdeclarative5-dev:armhf qtfeedback5-dev:armhf qtlocation5-dev:armhf qtmultimedia5-dev:armhf qtpim5-dev:armhf libqt5sensors5-dev:armhf qtsystems5-dev:armhf
$click chroot -aarmhf -fubuntu-sdk-14.10 maint
$ cordova build --device
liuxg@liuxg:~/web/myapp$ find ./ -name *.click ./platforms/ubuntu/ubuntu-sdk-14.10/armhf/prefix/myapp.mycompany_0.0.1_armhf.click
$ cordova run --device --debug
$ cordova build --device -- --framework ubuntu-sdk-15.04 --verbose
$ cordova run --device --debug -- --framework ubuntu-sdk-15.04
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
console.log("This shows how to output something to debug");
app.initialize();
$ cordova run --device --debug -- --framework ubuntu-sdk-15.04
This shows how to output something to debug
$ cordova run --debug
怎样在Ubuntu手机平台中开发Cordova HTML5应用
原文:http://www.cnblogs.com/blfbuaa/p/7056165.html