离子构建android错误

时间:2014-11-25 07:28:29

标签: android cordova windows-7-x64 ionic-framework

我对离子框架很新,我怎么能在Windows 7系统中运行并运行,但现在我正在尝试用离子框架构建一个Android应用程序,我按照以下步骤进行操作

>npm install -g cordova
>npm install -g ionic
>ionic start resistance blank
>cd resistance
>ionic platform add android

直到这里我做得很好,但是当我运行命令时

>ionic build android

我收到以下错误

    C:\Users\vishwant\resistance>ionic build android
Running command: "C:\Program Files\nodejs\node.exe" C:\Users\vishwant\resistance\hooks\after_prepare\010_add_platform_class.js C:\Users\vishwant\resis
tance
add to body class: platform-android
Running command: C:\Users\vishwant\resistance\platforms\android\cordova\build.bat

C:\Users\vishwant\resistance\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                          ^
Error: ENOENT, no such file or directory 'C:\adt-bundle-windows-x86_64-20140702\sdk\tools\tools\lib\build.template'
    at Object.fs.openSync (fs.js:432:18)
    at Object.fs.readFileSync (fs.js:289:15)
    at C:\Users\vishwant\resistance\platforms\android\cordova\lib\build.js:120:40
    at _fulfilled (C:\Users\vishwant\resistance\platforms\android\cordova\node_modules\q\q.js:798:54)
    at self.promiseDispatch.done (C:\Users\vishwant\resistance\platforms\android\cordova\node_modules\q\q.js:827:30)
    at Promise.promise.promiseDispatch (C:\Users\vishwant\resistance\platforms\android\cordova\node_modules\q\q.js:760:13)
    at C:\Users\vishwant\resistance\platforms\android\cordova\node_modules\q\q.js:574:44
    at flush (C:\Users\vishwant\resistance\platforms\android\cordova\node_modules\q\q.js:108:17)
    at process._tickCallback (node.js:419:13)
Error: C:\Users\vishwant\resistance\platforms\android\cordova\build.bat: Command failed with exit code 8
    at ChildProcess.whenDone (C:\Users\vishwant\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:135:23)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)

我注意到路径不正确,但在路径变量中我已正确设置,直到工具。

  

错误:ENOENT,没有这样的文件或目录   'C:\ ADT-束 - 窗口x86_64-20140702 \ SDK \工具\工具\ lib中\ build.template'

首先,我不明白为什么它会附加一个工具\并搜索build.template 其次,如果我手动创建工具\中的额外工具\文件夹\(我想避免),那么上面的错误消失了,但我会被显示

C:\Users\vishwant\resistance>ionic build android
Running command: "C:\Program Files\nodejs\node.exe" C:\Users\vishwant\resistance\hooks\after_prepare\010_add_platform_class.js C:\Users\vishwant\resis
tance
add to body class: platform-android
Running command: C:\Users\vishwant\resistance\platforms\android\cordova\build.bat
[Error: Please install Android target "android-19".
Hint: Run "android" from your command-line to open the SDK manager.]
Error: C:\Users\vishwant\resistance\platforms\android\cordova\build.bat: Command failed with exit code 2
    at ChildProcess.whenDone (C:\Users\vishwant\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:135:23)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)

由于我已经安装了android sdks和目标4.4W,这对于cordova项目来说工作正常,我不明白为什么离线框架失败了。

请纠正我如果我错过了什么。

由于

4 个答案:

答案 0 :(得分:10)

我想这是因为你将ANDROID_HOME设置为错误的路径。

ANDROID_HOME必须设置为android SDK的根目录,而不是工具文件夹:

SET ANDROID_HOME=C:\adt-bundle-windows-x86_64-20140702\sdk

但工具文件夹必须位于路径中。

SET PATH=%PATH%;%ANDROID_HOME%\tools

(当然使用windows设置来设置env vars,不要在cmd中这样做,这只是为了更清楚地解释)

答案 1 :(得分:3)

对于Mac OSX用户:您可以修改bashprofile

~ nano .bash_profile

然后将以下行添加到文件中并保存

export ANDROID_HOME=/usr/local/<path_to_your_androidsdk>/
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

重新启动系统并运行构建

ionic build android

花了一些时间来弄明白,希望有所帮助

答案 2 :(得分:1)

之前它是

export PATH=$PATH:$ANDROID_HOME/bin

现在是

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

希望它有所帮助:)

答案 3 :(得分:0)

确保您的android sdk路径设置正确。

以下是使用命令提示符设置然后重新启动它的方法:

SET ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk

SET PATH=%PATH%;%ANDROID_HOME%\tools

或者您可以从系统设置页面进行设置。