Phonegap build fails with exit code 2

2019-02-28 19:40发布

问题:

I just freshly installed phonegap and having this problem when I try to build the project with the following command ; "phonegap build android"

ANDROID_HOME : C:\Android\sdk

ANT_HOME : C:\apache-ant-1.9.4\

JAVA_HOME : C:\Program Files\Java\jdk1.8.0_45\

The detailed console log is as follows ;

Error : executing command 'ant' , make sure you have ant installed and added to your path. 
Command finished with error code 2: cmd ....\android\cordova\build.bat.
Error building one of the platforms. Error : cmd : command failed with exit code 2. 
You may not have the required environment or OS to build this project.

So it basically says that ANT is not working . When I type ANT into command prompt, it says ant is not recognized. %ANT_HOME/bin/ant works though.

When I do the following ANT command works but then phonegap is not recognized.

set  PATH=%BASEPATH% 
 set ANT_HOME=C:\apache-ant-1.9.4\
 set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_45\
 set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin;%PATH%

Any idea how to solve it ?

回答1:

Well it is so annoying.
In my app folder I did issue the following commands.

set ANT_HOME=C:\apache-ant-1.9.4\
set PATH=%PATH%;%ANT_HOME%\bin

And then the phonegap command works as well. Simply ANT is not resolved unless I issue the aforementioned commands. It took hours to try ANT command work but no light at all. It is simply not working even though it is defined as env variable.

Edit : If you also end up with the minSDK error each time you issue the phonegap build command ( which keeps happening for me right after I upgraded phonegap version to 5.0.0) , please keep in mind that editing manifest.xml wont make a difference because of the reason that it is edited back to its original form by the build command. What you need to do is to change the minSDK version in the www/config.xml file.