无法使用Cordova / Phonegap helloworld服务

时间:2014-05-13 13:41:35

标签: android cordova

我已安装Android SDK + Ant + cordova(3.4.1)+设置PATH变量(androidantcordova命令可用)

在cordova CLI的最后,有这样的例子:

Example usage

    $ cordova create Baz
    $ cd Baz
    $ cordova platform add android
    $ cordova build
    $ cordova serve android

-----------------------------------

所以我尝试了这个例子:

sebastien@sebastien-xps:Desktop$ cordova create Baz
Creating a new cordova project with name "HelloCordova" and id "io.cordova.hellocordova" at location "/home/sebastien/Desktop/Baz"

sebastien@sebastien-xps:Desktop$ cd Baz

sebastien@sebastien-xps:Baz$ cordova platform add android
Creating android project...
Creating Cordova project for the Android platform:
    Path: platforms/android
    Package: io.cordova.hellocordova
    Name: HelloCordova
    Android target: android-19
Copying template files...
Running: android update project --subprojects --path "platforms/android" --target android-19 --library "CordovaLib"
Resolved location of library project to: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib
Updated and renamed default.properties to project.properties
Updated local.properties
No project name specified, using Activity name 'HelloCordova'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/build.xml
Added file platforms/android/proguard-project.txt
Updated project.properties
Updated local.properties
No project name specified, using project folder name 'CordovaLib'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/CordovaLib/build.xml
Added file platforms/android/CordovaLib/proguard-project.txt

Project successfully created.

sebastien@sebastien-xps:Baz$ cordova build
Running command: /home/sebastien/Desktop/Baz/platforms/android/cordova/build 
Buildfile: /home/sebastien/Desktop/Baz/platforms/android/build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 22.6.2
 [checkenv] Installed at /home/sebastien/Desktop/devhome/install/adt-bundle-linux-x86_64-20140321/sdk

-setup:
     [echo] Project Name: HelloCordova
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.3
     [echo] Resolving Build Target for HelloCordova...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/ant-build
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/ant-build/res
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/ant-build/rsObj
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/ant-build/rsLibs
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/ant-gen
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/ant-build/classes
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/ant-build/dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for HelloCordova...
[dependency] Library dependencies:
[dependency] 
[dependency] ------------------
[dependency] Ordered libraries:
[dependency] 
[dependency] ------------------
     [echo] ----------
     [echo] Building Libraries with 'debug'...

nodeps:

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 22.6.2
 [checkenv] Installed at /home/sebastien/Desktop/devhome/install/adt-bundle-linux-x86_64-20140321/sdk

-setup:
     [echo] Project Name: CordovaLib
  [gettype] Project Type: Android Library

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.3
     [echo] Resolving Build Target for CordovaLib...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/res
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/libs
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/res
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/rsObj
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/rsLibs
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-gen
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/classes
    [mkdir] Created dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for CordovaLib...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------

-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 89 source files to /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/classes
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
     [echo] Creating library output jar file...
      [jar] Building jar: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/classes.jar

-post-compile:

-obfuscate:

-dex:
     [echo] Library project: do not convert bytecode...

-crunch:
   [crunch] Crunching PNG Files in source dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/res
   [crunch] To destination dir: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/res
   [crunch] Crunched 0 PNG files to update cache

-package-resources:
     [echo] Library project: do not package resources...

-package:
     [echo] Library project: do not package apk...

-post-package:

-do-debug:
     [echo] Library project: do not create apk...
[propertyfile] Creating new property file: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/build.prop

-post-build:

debug:

-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:
     [echo] Set jars path to: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/classes.jar

-compile:
    [javac] Compiling 3 source files to /home/sebastien/Desktop/Baz/platforms/android/ant-build/classes

-post-compile:

-obfuscate:

-dex:
      [dex] input: /home/sebastien/Desktop/Baz/platforms/android/ant-build/classes
      [dex] input: /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/classes.jar
      [dex] Pre-Dexing /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build/classes.jar -> classes-f44eaf7d8904b207eb36100ec05db9be.jar
      [dex] Converting compiled files and external libraries into /home/sebastien/Desktop/Baz/platforms/android/ant-build/classes.dex...
       [dx] Merged dex A (7 defs/2.2KiB) with dex B (205 defs/312.8KiB). Result is 212 defs/383.8KiB. Took 0.3s

-crunch:
   [crunch] Crunching PNG Files in source dir: /home/sebastien/Desktop/Baz/platforms/android/res
   [crunch] To destination dir: /home/sebastien/Desktop/Baz/platforms/android/ant-build/res
   [crunch] Processing image to cache: /home/sebastien/Desktop/Baz/platforms/android/res/drawable-hdpi/icon.png => /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable-hdpi/icon.png
   [crunch]   (processed image to cache entry /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable-hdpi/icon.png: 67% size of source)
   [crunch] Processing image to cache: /home/sebastien/Desktop/Baz/platforms/android/res/drawable-ldpi/icon.png => /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable-ldpi/icon.png
   [crunch]   (processed image to cache entry /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable-ldpi/icon.png: 0% size of source)
   [crunch] Processing image to cache: /home/sebastien/Desktop/Baz/platforms/android/res/drawable-mdpi/icon.png => /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable-mdpi/icon.png
   [crunch]   (processed image to cache entry /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable-mdpi/icon.png: 0% size of source)
   [crunch] Processing image to cache: /home/sebastien/Desktop/Baz/platforms/android/res/drawable-xhdpi/icon.png => /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable-xhdpi/icon.png
   [crunch]   (processed image to cache entry /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable-xhdpi/icon.png: 53% size of source)
   [crunch] Processing image to cache: /home/sebastien/Desktop/Baz/platforms/android/res/drawable/icon.png => /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable/icon.png
   [crunch]   (processed image to cache entry /home/sebastien/Desktop/Baz/platforms/android/ant-build/res/drawable/icon.png: 53% size of source)
   [crunch] Crunched 5 PNG files to update cache

-package-resources:
     [aapt] Creating full resource package...

-package:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating HelloCordova-debug-unaligned.apk and signing it with a debug key...

-post-package:

-do-debug:
 [zipalign] Running zip align on final apk...
     [echo] Debug Package: /home/sebastien/Desktop/Baz/platforms/android/ant-build/HelloCordova-debug.apk
[propertyfile] Creating new property file: /home/sebastien/Desktop/Baz/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /home/sebastien/Desktop/Baz/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /home/sebastien/Desktop/Baz/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /home/sebastien/Desktop/Baz/platforms/android/ant-build/build.prop

-post-build:
     [move] Moving 1 file to /home/sebastien/Desktop/Baz/platforms/android/ant-build
     [move] Moving 1 file to /home/sebastien/Desktop/Baz/platforms/android/CordovaLib/ant-build

debug:

BUILD SUCCESSFUL
Total time: 18 seconds

sebastien@sebastien-xps:Baz$ cordova serve android
Static file server running on port 8000 (i.e. http://localhost:8000)
CTRL + C to shut down
302 /android/
200 /android/www/
200 /android/www/css/index.css
200 /android/www/cordova.js
200 /android/www/js/index.js
200 /android/www/img/logo.png

乍一看似乎工作得很好。 我可以打开http://localhost:8000并显示一些内容:

Package Metadata

name    HelloCordova
packageName io.cordova.hellocordova
version 0.0.1


Platforms

ios
android
ubuntu
amazon-fireos
wp7
wp8
blackberry10
www
firefoxos
windows8


Plugins

我可以点击Android链接,问题是当我这样做时,会出现一个奇怪的对话框,其中包含question = [],要求我确认或取消以下文本预填充文字:

gap:["PluginManager","startup","PluginManager1413322690"]

接受之后,我可以看到背景Cordova, connecting to device但没有任何事情发生,除了看起来像我在控制台中可以看到的无限循环:

The key "target-densitydpi" is not supported. localhost/:25

Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only. cordova.js:966

698173
processMessage failed: invalid message: 

号码698173正在增长

有人能告诉我这种奇怪的行为是什么吗?

3 个答案:

答案 0 :(得分:15)

我知道这是一个老线程,但我今天遇到了同样的问题并且不想安装模拟器

您需要将浏览器平台添加到您的应用

cordova platform add browser

并将浏览器指向http://localhost:8000/browser/www/

答案 1 :(得分:5)

当您最初提示使用javascript对话框(例如gap:[“PluginManager”,...])时,您可以按取消以正确加载应用程序。

答案 2 :(得分:3)

在与Cordova开发人员讨论IRC后,serve命令在某种程度上没有得到很好的记录,并且最近向最近发布的Phonegap App Developer移动应用程序提供内容非常有用,据我所知,它现在打算为常规桌面浏览器提供应用程序。

对于桌面浏览器测试,到目前为止,我已经成功使用了Ripple模拟器(不是Chrome插件,似乎没有维护,但是NPM包)。

例如,您可以使用以下命令在浏览器phonegap应用中进行测试:

npm install -g ripple-emulator
ripple emulate

这可能会对您有所帮助:https://github.com/stample/gulp-browserify-react-phonegap-starter