PhoneGap - 构建错误

时间:2014-03-06 23:51:40

标签: cordova

我对phonegap很新,并尝试通过输入phonegap install网页上描述的命令来创建一个简单的测试应用

不幸的是,我在命令行中收到以下错误:

BUILD FAILED
E:\ProgramFiles(x86)\AndroidSDK\tools\ant\build.xml:892: The following error occ
urred while executing this line:
E:\ProgramFiles(x86)\AndroidSDK\tools\ant\build.xml:894: The following error occ
urred while executing this line:
E:\ProgramFiles(x86)\AndroidSDK\tools\ant\build.xml:906: The following error occ
urred while executing this line:
E:\ProgramFiles(x86)\AndroidSDK\tools\ant\build.xml:284: null returned: 1

Total time: 4 seconds
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,E:\Projects\Mobile\P
honeGap\test-app\platforms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.
dir=ant-gen
   [error] cmd: Command failed with exit code 2

我使用Windows 7 64位。我的环境变量如下所示:

ANDROID_HOME = E:\ProgramFiles(x86)\AndroidSDK
ANT_HOME = E:\Projects\Mobile\Eclipse\plugins\org.apache.ant_1.8.3.v201301120609
JAVA_HOME = C:\Program Files\Java\jdk1.7.0_51

然而,如果我在命令shell中键入“ant”,我会收到以下消息:

  

E:\项目\移动\的PhoneGap \测试应用程式>蚂蚁

     

Buildfile:build.xml不存在!

     

构建失败

这可能是原因吗?

感谢您的帮助!

编辑:

以下是命令行中的完整输出:

E:\Projects\Mobile\PhoneGap\test-app>phonegap run android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] compiling Android...
[ReferenceError: a is not defined]
Buildfile: E:\Projects\Mobile\PhoneGap\test-app\platforms\android\build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 22.3.0
 [checkenv] Installed at E:\ProgramFiles(x86)\AndroidSDK

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

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.0
     [echo] Resolving Build Target for HelloWorld...
[gettarget] Project Target:   Android 4.4
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: E:\Projects\Mobile\PhoneGap\test-app\platforms\android\
ant-build\rsObj
    [mkdir] Created dir: E:\Projects\Mobile\PhoneGap\test-app\platforms\android\
ant-build\rsLibs
     [echo] ----------
     [echo] Resolving Dependencies for HelloWorld...
[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.3.0
 [checkenv] Installed at E:\ProgramFiles(x86)\AndroidSDK

-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.0
     [echo] Resolving Build Target for CordovaLib...
[gettarget] Project Target:   Android 4.4
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: E:\Projects\Mobile\PhoneGap\test-app\platforms\android\
CordovaLib\ant-build\rsObj
    [mkdir] Created dir: E:\Projects\Mobile\PhoneGap\test-app\platforms\android\
CordovaLib\ant-build\rsLibs
     [echo] ----------
     [echo] Resolving Dependencies for CordovaLib...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------

-code-gen:
[mergemanifest] Found Deleted Target File
[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] Found new input file
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.

-pre-compile:

-compile:
     [echo] Creating library output jar file...

-post-compile:

-obfuscate:

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

-crunch:
   [crunch] Crunching PNG Files in source dir: E:\Projects\Mobile\PhoneGap\test-
app\platforms\android\CordovaLib\res
   [crunch] To destination dir: E:\Projects\Mobile\PhoneGap\test-app\platforms\a
ndroid\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] Updating property file: E:\Projects\Mobile\PhoneGap\test-app\plat
forms\android\CordovaLib\ant-build\build.prop
[propertyfile] Updating property file: E:\Projects\Mobile\PhoneGap\test-app\plat
forms\android\CordovaLib\ant-build\build.prop
[propertyfile] Updating property file: E:\Projects\Mobile\PhoneGap\test-app\plat
forms\android\CordovaLib\ant-build\build.prop
[propertyfile] Updating property file: E:\Projects\Mobile\PhoneGap\test-app\plat
forms\android\CordovaLib\ant-build\build.prop

-post-build:

debug:

-code-gen:
[mergemanifest] Found Deleted Target File
[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] Found Deleted Target File
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:
     [echo] Set jars path to: E:\Projects\Mobile\PhoneGap\test-app\platforms\and
roid\CordovaLib\ant-build\classes.jar

-compile:
    [javac] Compiling 2 source files to E:\Projects\Mobile\PhoneGap\test-app\pla
tforms\android\ant-build\classes

-post-compile:

-obfuscate:

-dex:
      [dex] input: E:\Projects\Mobile\PhoneGap\test-app\platforms\android\ant-bu
ild\classes
      [dex] input: E:\Projects\Mobile\PhoneGap\test-app\platforms\android\Cordov
aLib\ant-build\classes.jar
      [dex] Pre-Dexing E:\Projects\Mobile\PhoneGap\test-app\platforms\android\Co
rdovaLib\ant-build\classes.jar -> classes-e1aa4bb1e6a0a2f38f9e3036d5cbe6f6.jar
       [dx] 'E:\ProgramFiles' is not recognized as an internal or external comma
nd,
       [dx] operable program or batch file.

BUILD FAILED
E:\ProgramFiles(x86)\AndroidSDK\tools\ant\build.xml:892: The following error occ
urred while executing this line:
E:\ProgramFiles(x86)\AndroidSDK\tools\ant\build.xml:894: The following error occ
urred while executing this line:
E:\ProgramFiles(x86)\AndroidSDK\tools\ant\build.xml:906: The following error occ
urred while executing this line:
E:\ProgramFiles(x86)\AndroidSDK\tools\ant\build.xml:284: null returned: 1

Total time: 2 seconds
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,E:\Projects\Mobile\P
honeGap\test-app\platforms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.
dir=ant-gen
   [error] cmd: Command failed with exit code 2

7 个答案:

答案 0 :(得分:7)

重命名android文件夹并再次运行' phonegap本地构建android'当我遇到同样的错误时,为我工作。

答案 1 :(得分:5)

我通过删除这些文件夹的内容解决了这个问题:

/platforms/android/ant-build
/platforms/android/ant-gen
/platforms/android/bin
/platforms/android/gen

答案 2 :(得分:3)

在错误日志中,您会看到消息

E:\ProgramFiles' is not recognized as an internal or external command, operable program or batch file.

您配置ANDROID_HOME = E:\ProgramFiles(x86)\AndroidSDK这对我来说似乎很奇怪,因为通常该文件夹名为C:\Program Files (x86)(带空格)。

你的AndroidSDK真的安装在名为E:\ ProgramFiles(x86)的文件夹中吗? 我真的不认为这是问题,因为似乎找到了SDK,但我不得不问...

更有可能,我认为在cordova构建脚本中的某个地方可能会有一条不喜欢路径中圆括号()的行。

要在不弄乱你的conf的情况下使用它,你可以在cmd中尝试这个(关闭cmd后更改将会丢失):

subst z: E:\ProgramFiles(x86)\AndroidSDK
set ANDROID_HOME=z:\
phonegap build android

(如果您已使用Z驱动器,则将Z替换为其他lerrer)

答案 3 :(得分:3)

当您收到错误时

  

命令失败,退出代码为2

原因可能是因为您的Android SDK没有完全或正确安装。要解决此问题,您可以尝试编辑文件\platforms\android\project.properties并更改

target=android-22

类似

target=android-21

或者您过去成功构建应用的其他目标。这将下载一个新的gradle,这就是构建项目所需的全部内容。

答案 4 :(得分:2)

当您在version文件中将config.xml代码从“0.0.1”更改为“0.1”时会发生这种情况。

但根据PhoneGap文档,它必须是主要/次要/补丁:

  

元素的id属性提供应用程序的反向域   标识符,以及其完整版本号表示的版本   主要/次要/补丁表示法。

http://docs.phonegap.com/en/3.5.0/config_ref_index.md.html

答案 5 :(得分:2)

删除您的平台并重新添加。它解决了我的问题

删除android平台:

离子平台rm android

再次添加:

离子平台添加android

确保您备份res文件夹。如果你有任何图标或启动画面..

答案 6 :(得分:1)

我的故事是我设法拥有两个 node_modules个文件夹,一个位于我的Phonegap项目的根目录,另一个位于AngularJS应用程序的www内正试图" port"使用Phonegap。我收到了一个堆栈跟踪,例如

..
unable to process assets while packaging
<..>\node_modules\semver\semver.browser.js.gz': file already in archive (try '-u'?)
..
<..>\android-sdk\tools\ant\build.xml:950: null returned: 1

还收到了\cordova\build.bat: Command failed with exit code 8,但我不知道这两个错误是否相关。

node_modules文件夹中删除www文件夹就可以了。运行Win7 x64。