如何将Windows Phone 8应用程序(使用Cordova / PhoneGap完成)转换为Android应用程序

时间:2014-02-11 16:18:17

标签: android cordova windows-phone-8 windows-phone

更新

我按照benka和MBillau给出的指示,然后我成功生成并构建了Android项目!!很开心!

现在我被困在Android模拟器上模拟项目了。以下是运行模拟命令时收到的错误消息:

F:\Workplace\Cordova3.3.1>cordova emulate android
Generating config.xml from defaults for platform "android"
Preparing android project
Running on emulator for platform "android" via command "cmd" /c F:\Workplace\Cordova3.3.1\platforms\android\cordova\run --emulator
Error: An error occurred while emulating/deploying the android project.
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)

    at ChildProcess.<anonymous> (C:\Users\franv_000\AppData\Roaming\npm\node_modules\cordova\src\emulate.js:67:22)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Socket.<anonymous> (child_process.js:948:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:466:12)

在构建Android项目时我确实遇到了另一个错误,但是那个错误信息是清晰且具有描述性的,所以我很容易修复它。但是这个错误信息让人感到困惑,并且不知道该去哪里才能找到解决方案。

您的帮助和时间将不胜感激!


首先,我想感谢PhoneGap / Cordova,它为我们提供了出色的能力。

现在,我已经使用Cordova在WP8平台上完成了我的开发,我已经为Android开发设置了环境(安装了Java,Ant,Android开发工具以及Eclipse,模拟器并创建了虚拟Android手机)

我还使用CLI添加Android平台,因此我在平台文件夹下找到了一个文件夹:Android。

当我打开该文件夹时,我希望看到与我在wp8文件夹下看到的类似的文件夹结构,但它完全不同。 说实话,我甚至不知道我应该将我的index.html复制到哪个文件夹。 我查看了Cordova / PhoneGap的文档。但一无所获。 实际上,关于如何将移动应用程序从A平台转换为B平台的一套指南应放在该网站上一个非常明显的位置(毕竟,使用PhoneGap / Cordova的主要目的是编码一次,然后生成应用程序在不同的移动平台上轻松)

如果有人可以帮我解决这个问题并给我明确的指导方针,我很感激。

提前谢谢。

更新2:运行cordova emulate -d android

时的错误日志
F:\Workplace\Cordova3.3.1>cordova emulate -d android
cordova library for "android" already exists. No need to download. Continuing.
Generating config.xml from defaults for platform "android"
Calling plugman.prepare for platform "android"
Preparing android project
Processing configuration changes for plugins.
Iterating over installed plugins: [ 'org.apache.cordova.contacts',
  'org.apache.cordova.device',
  'org.apache.cordova.device-motion',
  'org.apache.cordova.device-orientation',
  'org.apache.cordova.dialogs',
  'org.apache.cordova.geolocation',
  'org.apache.cordova.network-information',
  'org.apache.cordova.splashscreen',
  'org.apache.cordova.vibration' ]
Writing out cordova_plugins.js...
Ensuring plugin "org.apache.cordova.contacts" is installed correctly...
Plugin "org.apache.cordova.contacts" is good to go.
Ensuring plugin "org.apache.cordova.device" is installed correctly...
Plugin "org.apache.cordova.device" is good to go.
Ensuring plugin "org.apache.cordova.device-motion" is installed correctly...
Plugin "org.apache.cordova.device-motion" is good to go.
Ensuring plugin "org.apache.cordova.device-orientation" is installed correctly...
Plugin "org.apache.cordova.device-orientation" is good to go.
Ensuring plugin "org.apache.cordova.dialogs" is installed correctly...
Plugin "org.apache.cordova.dialogs" is good to go.
Ensuring plugin "org.apache.cordova.geolocation" is installed correctly...
Plugin "org.apache.cordova.geolocation" is good to go.
Ensuring plugin "org.apache.cordova.network-information" is installed correctly...
Plugin "org.apache.cordova.network-information" is good to go.
Ensuring plugin "org.apache.cordova.splashscreen" is installed correctly...
Plugin "org.apache.cordova.splashscreen" is good to go.
Ensuring plugin "org.apache.cordova.vibration" is installed correctly...
Plugin "org.apache.cordova.vibration" is good to go.
Wrote out Android application name to "MCBTimetable"
Wrote out Android package name to "io.cordova.MCBTimetable"
Running on emulator for platform "android" via command "cmd" /c F:\Workplace\Cordova3.3.1\platforms\android\cordova\run --emulator
exec: ant clean -f "F:\Workplace\Cordova3.3.1\platforms\android\build.xml"

[ 'ant clean -f "F:\\Workplace\\Cordova3.3.1\\platforms\\android\\build.xml"',
  null,
  'Buildfile: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\build.xml\r\n\r\n-check-env:\r\n [checkenv] Android SDK Tools Revision 22.3.0\r\n [checkenv] Inst
alled at D:\\Installation packages\\Java\\adt-bundle-windows-x86_64-20131030\\adt-bundle-windows-x86_64-20131030\\sdk\r\n\r\n-setup:\r\n     [echo] Project Name
: MCBTimetable\r\n  [gettype] Project Type: Application\r\n\r\n-pre-clean:\r\n\r\nclean:\r\n   [delete] Deleting directory F:\\Workplace\\Cordova3.3.1\\platform
s\\android\\bin\r\n   [delete] Deleting directory F:\\Workplace\\Cordova3.3.1\\platforms\\android\\gen\r\n[getlibpath] Library dependencies:\r\n[getlibpath] \r\
n[getlibpath] ------------------\r\n[getlibpath] Ordered libraries:\r\n\r\nnodeps:\r\n\r\n-check-env:\r\n [checkenv] Android SDK Tools Revision 22.3.0\r\n [chec
kenv] Installed at D:\\Installation packages\\Java\\adt-bundle-windows-x86_64-20131030\\adt-bundle-windows-x86_64-20131030\\sdk\r\n\r\n-setup:\r\n     [echo] Pr
oject Name: CordovaLib\r\n  [gettype] Project Type: Android Library\r\n\r\n-pre-clean:\r\n\r\nclean:\r\n   [delete] Deleting directory F:\\Workplace\\Cordova3.3
.1\\platforms\\android\\CordovaLib\\bin\r\n   [delete] Deleting directory F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\gen\r\n\r\nBUILD SUCCESSF
UL\r\nTotal time: 1 second\r\n',
  '' ]

exec: ant debug -f "F:\Workplace\Cordova3.3.1\platforms\android\build.xml"

[ 'ant debug -f "F:\\Workplace\\Cordova3.3.1\\platforms\\android\\build.xml"',
  null,
  'Buildfile: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\build.xml\r\n\r\n-set-mode-check:\r\n\r\n-set-debug-files:\r\n\r\n-check-env:\r\n [checkenv] Andr
oid SDK Tools Revision 22.3.0\r\n [checkenv] Installed at D:\\Installation packages\\Java\\adt-bundle-windows-x86_64-20131030\\adt-bundle-windows-x86_64-2013103
0\\sdk\r\n\r\n-setup:\r\n     [echo] Project Name: MCBTimetable\r\n  [gettype] Project Type: Application\r\n\r\n-set-debug-mode:\r\n\r\n-debug-obfuscation-check
:\r\n\r\n-pre-build:\r\n\r\n-build-setup:\r\n[getbuildtools] Using latest Build Tools: 19.0.0\r\n     [echo] Resolving Build Target for MCBTimetable...\r\n[gett
arget] Project Target:   Android 4.4.2\r\n[gettarget] API level:        19\r\n     [echo] ----------\r\n     [echo] Creating output directories if needed...\r\n
    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\
res\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\rsObj\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\
android\\bin\\rsLibs\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\gen\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\p
latforms\\android\\bin\\classes\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\dexedLibs\r\n     [echo] ----------\r\n     [e
cho] Resolving Dependencies for MCBTimetable...\r\n[dependency] Library dependencies:\r\n[dependency] \r\n[dependency] ------------------\r\n[dependency] Ordere
d libraries:\r\n[dependency] \r\n[dependency] ------------------\r\n     [echo] ----------\r\n     [echo] Building Libraries with \'debug\'...\r\n\r\nnodeps:\r\
n\r\n-set-mode-check:\r\n\r\n-set-debug-files:\r\n\r\n-check-env:\r\n [checkenv] Android SDK Tools Revision 22.3.0\r\n [checkenv] Installed at D:\\Installation
packages\\Java\\adt-bundle-windows-x86_64-20131030\\adt-bundle-windows-x86_64-20131030\\sdk\r\n\r\n-setup:\r\n     [echo] Project Name: CordovaLib\r\n  [gettype
] Project Type: Android Library\r\n\r\n-set-debug-mode:\r\n\r\n-debug-obfuscation-check:\r\n\r\n-pre-build:\r\n\r\n-build-setup:\r\n[getbuildtools] Using latest
 Build Tools: 19.0.0\r\n     [echo] Resolving Build Target for CordovaLib...\r\n[gettarget] Project Target:   Android 4.4.2\r\n[gettarget] API level:        19\
r\n     [echo] ----------\r\n     [echo] Creating output directories if needed...\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\C
ordovaLib\\bin\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\bin\\res\r\n    [mkdir] Created dir: F:\\Workplace\\Cord
ova3.3.1\\platforms\\android\\CordovaLib\\bin\\rsObj\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\bin\\rsLibs\r\n
 [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\gen\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\andro
id\\CordovaLib\\bin\\classes\r\n    [mkdir] Created dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\bin\\dexedLibs\r\n     [echo] ----------\r
\n     [echo] Resolving Dependencies for CordovaLib...\r\n[dependency] Library dependencies:\r\n[dependency] No Libraries\r\n[dependency] \r\n[dependency] -----
-------------\r\n\r\n-code-gen:\r\n[mergemanifest] Merging AndroidManifest files into one.\r\n[mergemanifest] Manifest merger disabled. Using project manifest o
nly.\r\n     [echo] Handling aidl files...\r\n     [aidl] No AIDL files to compile.\r\n     [echo] ----------\r\n     [echo] Handling RenderScript files...\r\n
    [echo] ----------\r\n     [echo] Handling Resources...\r\n     [aapt] Generating resource IDs...\r\n     [echo] ----------\r\n     [echo] Handling BuildConf
ig class...\r\n[buildconfig] Generating BuildConfig class.\r\n\r\n-pre-compile:\r\n\r\n-compile:\r\n    [javac] Compiling 73 source files to F:\\Workplace\\Cord
ova3.3.1\\platforms\\android\\CordovaLib\\bin\\classes\r\n    [javac] Note: Some input files use or override a deprecated API.\r\n    [javac] Note: Recompile wi
th -Xlint:deprecation for details.\r\n     [echo] Creating library output jar file...\r\n      [jar] Building jar: F:\\Workplace\\Cordova3.3.1\\platforms\\andro
id\\CordovaLib\\bin\\classes.jar\r\n\r\n-post-compile:\r\n\r\n-obfuscate:\r\n\r\n-dex:\r\n     [echo] Library project: do not convert bytecode...\r\n\r\n-crunch
:\r\n   [crunch] Crunching PNG Files in source dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\res\r\n   [crunch] To destination dir: F:\\Work
place\\Cordova3.3.1\\platforms\\android\\CordovaLib\\bin\\res\r\n   [crunch] Crunched 0 PNG files to update cache\r\n\r\n-package-resources:\r\n     [echo] Libr
ary project: do not package resources...\r\n\r\n-package:\r\n     [echo] Library project: do not package apk...\r\n\r\n-post-package:\r\n\r\n-do-debug:\r\n
[echo] Library project: do not create apk...\r\n[propertyfile] Creating new property file: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\bin\\bui
ld.prop\r\n[propertyfile] Updating property file: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\bin\\build.prop\r\n[propertyfile] Updating proper
ty file: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\bin\\build.prop\r\n[propertyfile] Updating property file: F:\\Workplace\\Cordova3.3.1\\pla
tforms\\android\\CordovaLib\\bin\\build.prop\r\n\r\n-post-build:\r\n\r\ndebug:\r\n\r\n-code-gen:\r\n[mergemanifest] Merging AndroidManifest files into one.\r\n[
mergemanifest] Manifest merger disabled. Using project manifest only.\r\n     [echo] Handling aidl files...\r\n     [aidl] No AIDL files to compile.\r\n     [ec
ho] ----------\r\n     [echo] Handling RenderScript files...\r\n     [echo] ----------\r\n     [echo] Handling Resources...\r\n     [aapt] Generating resource I
Ds...\r\n     [echo] ----------\r\n     [echo] Handling BuildConfig class...\r\n[buildconfig] Generating BuildConfig class.\r\n\r\n-pre-compile:\r\n\r\n-compile
:\r\n    [javac] Compiling 17 source files to F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\classes\r\n\r\n-post-compile:\r\n\r\n-obfuscate:\r\n\r\n-dex
:\r\n      [dex] input: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\classes\r\n      [dex] input: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\Cor
dovaLib\\bin\\classes.jar\r\n      [dex] Pre-Dexing F:\\Workplace\\Cordova3.3.1\\platforms\\android\\CordovaLib\\bin\\classes.jar -> classes-a9bfeb13801703244de
81d2eb7af0f8a.jar\r\n      [dex] Converting compiled files and external libraries into F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\classes.dex...\r\n
      [dx] Merged dex A (46 defs/73.9KiB) with dex B (174 defs/271.6KiB). Result is 220 defs/420.7KiB. Took 0.2s\r\n\r\n-crunch:\r\n   [crunch] Crunching PNG Fi
les in source dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\res\r\n   [crunch] To destination dir: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\
\res\r\n   [crunch] Processing image to cache: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\res\\drawable-hdpi\\icon.png => F:\\Workplace\\Cordova3.3.1\\pla
tforms\\android\\bin\\res\\drawable-hdpi\\icon.png\r\n   [crunch]   (processed image to cache entry F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\res\\d
rawable-hdpi\\icon.png: 67% size of source)\r\n   [crunch] Processing image to cache: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\res\\drawable-ldpi\\icon.
png => F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\res\\drawable-ldpi\\icon.png\r\n   [crunch]   (processed image to cache entry F:\\Workplace\\Cordov
a3.3.1\\platforms\\android\\bin\\res\\drawable-ldpi\\icon.png: 0% size of source)\r\n   [crunch] Processing image to cache: F:\\Workplace\\Cordova3.3.1\\platfor
ms\\android\\res\\drawable-mdpi\\icon.png => F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\res\\drawable-mdpi\\icon.png\r\n   [crunch]   (processed imag
e to cache entry F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\res\\drawable-mdpi\\icon.png: 0% size of source)\r\n   [crunch] Processing image to cache
: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\res\\drawable-xhdpi\\icon.png => F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\res\\drawable-xhdpi\\i
con.png\r\n   [crunch]   (processed image to cache entry F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\res\\drawable-xhdpi\\icon.png: 53% size of source
)\r\n   [crunch] Processing image to cache: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\res\\drawable\\icon.png => F:\\Workplace\\Cordova3.3.1\\platforms\\
android\\bin\\res\\drawable\\icon.png\r\n   [crunch]   (processed image to cache entry F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\res\\drawable\\icon
.png: 53% size of source)\r\n   [crunch] Crunched 5 PNG files to update cache\r\n\r\n-package-resources:\r\n     [aapt] Creating full resource package...\r\n
  [aapt] Warning: AndroidManifest.xml already defines debuggable (in http://schemas.android.com/apk/res/android); using existing value in manifest.\r\n\r\n-pack
age:\r\n[apkbuilder] Current build type is different than previous build: forced apkbuilder run.\r\n[apkbuilder] Creating MCBTimetable-debug-unaligned.apk and s
igning it with a debug key...\r\n\r\n-post-package:\r\n\r\n-do-debug:\r\n [zipalign] Running zip align on final apk...\r\n     [echo] Debug Package: F:\\Workpla
ce\\Cordova3.3.1\\platforms\\android\\bin\\MCBTimetable-debug.apk\r\n[propertyfile] Creating new property file: F:\\Workplace\\Cordova3.3.1\\platforms\\android\
\bin\\build.prop\r\n[propertyfile] Updating property file: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\build.prop\r\n[propertyfile] Updating property
file: F:\\Workplace\\Cordova3.3.1\\platforms\\android\\bin\\build.prop\r\n[propertyfile] Updating property file: F:\\Workplace\\Cordova3.3.1\\platforms\\android
\\bin\\build.prop\r\n\r\n-post-build:\r\n\r\ndebug:\r\n\r\nBUILD SUCCESSFUL\r\nTotal time: 15 seconds\r\n',
  '' ]

exec: adb devices

[ 'adb devices', null, 'List of devices attached \r\n\r\n', '' ]

exec: adb devices

[ 'adb devices', null, 'List of devices attached \r\n\r\n', '' ]

exec: android list avds

[ 'android list avds',
  null,
  'Available Android Virtual Devices:\n    Name: MyVA\n    Path: C:\\Users\\franv_000\\.android\\avd\\MyVA.avd\n  Target: Android 4.4.2 (API level 19)\n     ABI
: armeabi-v7a\n    Skin: 768x1280\n',
  '' ]

exec: android list avds

[ 'android list avds',
  null,
  'Available Android Virtual Devices:\n    Name: MyVA\n    Path: C:\\Users\\franv_000\\.android\\avd\\MyVA.avd\n  Target: Android 4.4.2 (API level 19)\n     ABI
: armeabi-v7a\n    Skin: 768x1280\n',
  '' ]


events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)

child_process.spawn(cmd,[/c, F:\Workplace\Cordova3.3.1\platforms\android\cordova\run, --emulator]) = 8
Error: An error occurred while emulating/deploying the android project.
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)

    at ChildProcess.<anonymous> (C:\Users\franv_000\AppData\Roaming\npm\node_modules\cordova\src\emulate.js:67:22)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Socket.<anonymous> (child_process.js:948:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:466:12)

2 个答案:

答案 0 :(得分:3)

当您通过 CLI 添加android platform时,它应该创建所有必需的文件夹并从主www文件夹中复制您的共享代码(假设您有共享代码)主www文件夹,而不是platform/wp8)。

您的index.html应该进入/www文件夹。然后,当您添加platform/android/assets/www平台或使用CLI工具构建应用程序时,它将被复制到Android文件夹。 (感谢@MBillau的输入,因为它应该更清楚。)

如果您为 WP8 应用程序实现了任何本机代码,您可能还需要为 Android 应用程序实现它。

答案 1 :(得分:1)

关于更新问题的解决方案,我发现了,这是做什么的:

只需在手动启动模拟器后运行。

  1. 使用UI创建模拟器 在cmd中键入android并按Enter键,GUI将会出现。 在工具部分下,单击“管理AVD”并按照进一步说明创建新的AVD。

  2. 启动模拟器 cmd中的emulator.exe -avd avdname (等待几分钟才能完全启动) 现在重新运行cordova。它会起作用。

  3. Cordova android emulator stopped working