" cordova运行ubuntu"产生不完整的应用

时间:2016-01-03 23:44:07

标签: cordova ubuntu

我正在尝试为ubuntu平台构建并运行一个cordova项目。该项目只是我创建新项目时自动生成的默认项目。这是config.xml文件(我添加了包含图标链接的行):

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.gregory.example" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<icon src="img/logo.png" > </icon>
    <name>Example</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="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>
</widget>

当我在浏览器中查看index.html文件时,会看到cordova徽标,以及一个闪烁的按钮,上面写着&#34;连接到设备。&#34;但是当我尝试使用CLI运行它时,它不起作用。

以下是我使用的命令:

gregory@gregory-1001PXD:~/javascript$ sudo cordova create example com.gregory.example Example
Creating a new cordova project.
gregory@gregory-1001PXD:~/javascript$ cd example/
gregory@gregory-1001PXD:~/javascript/example$ sudo vi config.xml 
gregory@gregory-1001PXD:~/javascript/example$ sudo cordova platform add ubuntu
Adding ubuntu project...
Running command: /home/gregory/.cordova/lib/npm_cache/cordova-ubuntu/4.0.0/package/bin/create /home/gregory/javascript/example/platforms/ubuntu com.gregory.example Example
Creating a Cordova Project:
 Project Path: /home/gregory/javascript/example/platforms/ubuntu
 Package Name: com.gregory.example
 Project Name: Example

missing icon element in config.xml
Discovered plugin "cordova-plugin-whitelist" in config.xml. Installing to the project
Fetching plugin "cordova-plugin-whitelist@1" via npm
Installing "cordova-plugin-whitelist" for ubuntu

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.

gregory@gregory-1001PXD:~/javascript/example$ sudo cordova build ubuntu
Running command: /home/gregory/javascript/example/platforms/ubuntu/cordova/build 
Building Desktop Application...
In order to build debian package, execute: 
cd /home/gregory/javascript/example/platforms/ubuntu/native/com.gregory.example; debuild
gregory@gregory-1001PXD:~/javascript/example$ sudo cordova run ubuntu
Running command: /home/gregory/javascript/example/platforms/ubuntu/cordova/run 
Building Desktop Application...
In order to build debian package, execute: 
cd /home/gregory/javascript/example/platforms/ubuntu/native/com.gregory.example; debuild
Build Successful. Running the application.
Running Cordova
Launching the application.

但在它说&#34;启动应用程序之后,&#34;弹出一个空的灰色窗口,侧边栏中显示的图标是一个问号。这里发生了什么?

1 个答案:

答案 0 :(得分:0)

当我按照别人对我的另一个问题的回答时,这个问题就解决了:

Failed to find 'ANDROID_HOME' environment variable. Failed to find 'android' command in your 'PATH'

具体来说,这是一个权限问题。我通过反复运行来修复它

cordova build ubuntu

没有 sudo,然后,每当出现权限错误时,我都会让非root用户访问相关文件或文件夹,例如

sudo chown -R gregory /home/gregory/.cordova/lib/npm_cache/cordova-android/4.1.1/package/.npmignore

执行此操作几次后,build命令最终执行且没有错误,然后

cordova run ubuntu

成功了。