PhoneGap Cordova Build Error Exit Code 2 - android

I'minstalled PhoneGap and made one simple app that works on my tablet when using PhoneGap server and PhoneGap App for android. Now I want to makean APK but I'm gatting error when runsudo phonegap build android in APP folder:
miljan#Miljan-PC:~/Desktop/HelloWorld$ sudo phonegap build android
[sudo] password for miljan: [phonegap] executing 'cordova build
android'... cp: no such file or directory:
/home/miljan/Desktop/HelloWorld/icon.png
Running command:
/home/miljan/Desktop/HelloWorld/platforms/android/cordova/build
[Error: ANDROID_HOME is not set and "android" command not in your
PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error:
/home/miljan/Desktop/HelloWorld/platforms/android/cordova/build:
Command failed with exit code 2 You may not have the required
environment or OS to build this project
Error:
/home/miljan/Desktop/HelloWorld/platforms/android/cordova/build:
Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
In ~/.profile I have add this:
export ANDROID_HOME=/home/miljan/Android-SDK-Linux
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools
How I can slove this problem?
Anyone who can help?

I had the same problem when I was using ionic to build android. I used this solution to solve my problem
Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
use the third solution and don't use the exact paths which are given here. In the android_home give the path of your sdk. in the android_tools give the path of tools in the sdk and in the third give the platform path given in the sdk.
and if you have problem after this too userchmod 777 /sdk/tools and chmod 777 /sdk/tools/android.
May this solution helps

Related

Cordova CLI can't find Android SDK using Windows 10

I have set my Environment Variables, yet I continue to get the following error:
[Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.]
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
Error: cmd: Command failed with exit code 2
at ChildProcess.whenDone (C:\Users\oneilj\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:139:23)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:818:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
I have uninstalled Android Studio and all the SDKs, and even un-installed nodeJS and cordova. After re-installing everything I still get the error.
I found this while waiting for an answer. The fix was from another user's question and answer:
Download tools_r25.2.3-windows.zip from Android Downloads.
Extracted zip on desktop
Replaced C:\Users\username\AppData\Local\Android\sdk\tools with extracted sub-folder tools/
In project folder:
$ cordova platforms remove android
$ cordova platforms add android

can't build cordova project, PATH error

while running cordova build from my app directory i get following error
[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.]
ERROR building one of the platforms: Error: /home/shakir/Documents/myapp/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/shakir/Documents/myapp/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
I have set my ~/.profile file as follows
export ANDROID_HOME="/usr/local/android-sdk-linux"
export ANDROID_PLATFORM_TOOLS="/usr/local/android-sdk-linux/platform-tools"
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_PLATFORM_TOOLS
and echo ANDROID_HOME give following results
/usr/local/android-sdk-linux
I am using Ubuntu 14.04. How to solve this issue and build cordova apps?
This error occurs, because of you didn't set your android sdk path correctly.
First, find where the android-sdk folder located in your computer. Inside the android-sdk folder, there is a folder called 'platform-tools'. So you can identify android-sdk folder correctly. Then get the path to the android-sdk folder. Now open the terminal and enter following command,
export ANDROID_HOME="your android-sdk path"
Now run the project.
you have probably used "sudo" for adding android platform.. a quick solution for this problem is:
Restore the right folder permission to all the folder/subfolder of the platforms folder
Delete the android platform with sudo cordova platform remove android
Add the android platform with cordova platform add android DON'T USE THE SUDO! If there are errors without the sudo SO that's the problem! NEVER use the sudo thing or the project will have issue like this!
if you still have a problem then you may have installed cordova using sudo, also there is a solution for it:
first we have to set up npm for global installation so we can use it without sudo, the preferred way of enabling npm to install packages globally without breaking out of $HOME is to set a local node prefix. This is as easy as running:
echo prefix = ~/.node >> ~/.npmrc
echo 'export PATH=$HOME/.node/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
then Running:
npm install -g cordova
it may results in:
Error: EACCES, permission denied '/home/yourusername/.config/configstore/update-notifier-cordova.json'
to fix it:
sudo chown yourusername:yourusername /home/yourusername/.config/configstore/update-notifier-cordova.json
After that, you can happily run npm install -g cordova without sudo, without running into permission conflicts and if something is completely broken and you want to start from scratch, all you need to do is remove your ~/.node directory.
Hope this help!
you can also look at these two links: source 1&2
Run following command in terminal :
export
PATH=${PATH}:/Users/Document/Android-sdk/tools:/Users/Documents/Android-sdk/platform-tools
You may also get this Error
Error: EACCES: permission denied, open '/home/yourusername/.cordova/lib/npm_cache/cordova-android/5.1.1/package/.npmignore'
to fix it use this command
sudo chown -R yourusername:yourusername /home/{username}/.cordova/lib/npm_cache/cordova-android/5.1.1/package

cordova build android throws error on Ubuntu 12.04

The issue looks very familiar with this
Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
But I am not able to fix it. When I run
% sudo cordova build android
I am getting the following error
Running command: /home/thabung/mobile/hello/platforms/android/cordova/build
[Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error: /home/thabung/mobile/hello/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/thabung/mobile/hello/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:766:16)
at Process.ChildProcess._handle.onexit (child_process.js:833:5)
Few things I am observing
% echo $ANDROID_HOME
returns me
~/mobile/android-sdk-linux
which is perfect location
& android command also works fine.
Please help..
I am using cordova 4.3.0
This ...
sudo cordova build android
runs in the environment of root whereas this ...
echo $ANDROID_HOME
was not executed as root. Check what echo $ANDROID_HOME returns as root - or (strongly recommended) - run Cordova as another user than root.
p.s.: I'm running Cordova 4.0.0 on Ubuntu 14.04 without sudo.

Cordova build issue in ubuntu

I was following the tutorials # http://www.gaggl.com/2014/04/apache-cordova-development-environment-install-on-ubuntu/
Cordova build is failing with message:
:~/projects/Hello$ sudo cordova build
Running command: /home/skn/projects/Hello/platforms/android/cordova/build
[Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error: /home/skn/projects/Hello/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/skn/projects/Hello/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:766:16)
at Process.ChildProcess._handle.onexit (child_process.js:833:5)
I have included the android in the path variable also.
skn#bangre:~/projects/Hello$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/bin/java:/usr/bin/ant:.:/home/skn/android-sdk-linux/tools:/home/skn/android-sdk-linux/platform-tools
From screenshot below you can see the sdk is installed
Also I have the following check which is passing.
skn#bangre:~/.cordova/lib/npm_cache/cordova-android/3.7.1/package/bin$ ./android_sdk_version
21
skn#bangre:~/.cordova/lib/npm_cache/cordova-android/3.7.1/package/bin$ ./check_reqs
Looks like your environment fully supports cordova-android development!
Please help me point out the issue.
yes turns out the cordova node.js scripts assumes the android sdk directory name as 'android-sdk' , for ubuntu when we unzip we get 'android-linux-sdk'

ionic build android error

I'm very new to the ionic framework,how ever I've cordova up and running in the windows 7 system but now I'm trying to build an android app with ionic framework and i followed the following steps
>npm install -g cordova
>npm install -g ionic
>ionic start resistance blank
>cd resistance
>ionic platform add android
Till here I'm doing good but when I run the command
>ionic build android
i get the following error
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)
I notice that the path is incorrect , but in the path variable I've set up correctly i.e till tools.
Error: ENOENT, no such file or directory
'C:\adt-bundle-windows-x86_64-20140702\sdk\tools\tools\lib\build.template'
Firstly,I don't understand why it's attaching one more tools\ and searching for the build.template
Secondly, If i manual create that extra tools\ folder inside the tools\ (which i want to avoid) then this above error is gone but i will be shown
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)
Since I've already installed android sdks and the targets 4.4W which is working fine for the cordova projects, I don't understand why it's failing for the ionic framework.
Please correct me If I'm missing out something.
Thanks
I guess it's because you set ANDROID_HOME to the wrong path.
ANDROID_HOME must be set to the root of the android SDK, not to tools folder:
SET ANDROID_HOME=C:\adt-bundle-windows-x86_64-20140702\sdk
But the tools folder must be in the path.
SET PATH=%PATH%;%ANDROID_HOME%\tools
(of course use windows settings to set env vars, don't do it in cmd, that was just to explain more clearly)
For Mac OSX users: you can modify your bashprofile
~ nano .bash_profile
Then add the following lines to the file and save it
export ANDROID_HOME=/usr/local/<path_to_your_androidsdk>/
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Reboot your system and run a build
ionic build android
Took me some time to figure that out, hope it helps
Earlier it was
export PATH=$PATH:$ANDROID_HOME/bin
Now it's
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
hope it helps :)
Make sure your android sdk path is set correctly.
Here is the way to set using command prompt then restart it:
SET ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
SET PATH=%PATH%;%ANDROID_HOME%\tools
or you can set it from system setting page.

Categories

Resources