9

I've installed Android SDK + Ant + cordova (3.4.1) + set PATH variables (android, ant, cordova commands are available)

At the end of the cordova CLI, there's this exemple usage:

Example usage

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

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

So I tried just that exemple:

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

This seems to work fine at first glance. I can open http://localhost:8000 and it displays something:

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

I can click on the Android link, the problem is when I do so, a strange dialog box appears with question = [], asking me to confirm or cancel the following text prefilled text:

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

After accepting, I can see the background Cordova, connecting to device but nothing happens except something that looks like an infinite loop that I can see in the console:

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: 

The number 698173 is growing

Can someone tell me what is this strange behavior?

4

3 回答 3

15

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

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

cordova platform add browser

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

于 2015-05-08T20:31:24.663 回答
5

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

于 2014-06-04T16:49:20.873 回答
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

于 2014-07-03T23:14:44.770 回答