Error building Android project in Cordova - android

I am new to Cordova and I am trying to build my project, which was previously working. I believe I have a bug. I am not very experienced with the terminal so I don't know how to resolve this. I have tried uninstalling and reinstalling cordova, as well as updating it with no success. Here is my error:
[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: /Users/joshuaoconnor/Desktop/PBBars/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /Users/joshuaoconnor/Desktop/PBBars/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:134:23)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
and here is the full image of the terminal

Your running in a standard "beginners" issue by using cordova or phonegap - but no problem, we are here to help you ;-)
The Terminal tells you, that:
ANDROID_HOME is not set and "android" command not in your PATH.
So, you $PATH is a SystemVariable which "saves" pathes to important files and folders. All files, which are part of the SystemVariable $PATH can be called via your Terminal. So because i don't know, which OS you are using, i'm going to post two solutions. One for each, mac and windows.
Before you start: The PATH is a SystemVariable which is needed as it is. Another folder can be added by a : which seperates the single folders and pathes inside your PATH. If you do anything wrong there, your system may never work correct again without reinstalling it - be carefull and do not delete any of the PATHs content which is already there.
What do i need in my Path? (especially for Cordova/PhoneGap now)
So you need three things in your Path:
%ANDROID_HOME%
tools
platform-tools
How can i see my actual $PATH?
echo $PATH on a mac
echo %PATH% on windows
How to set up the PATH Variable on Windows
Select your Computer from the Start Menu.
From the Contextmenu select System properties.
After that select the advanced tab.
In that section you click on Environment Variables.
So in the section System variables you're going to find the Path which can be edited over there.
How to set up the PATH Variable on Mac OS X Yosemite
Open your terminal and go on like this:
vi $HOME/.bash_profile
Add a line there with this content:
export PATH=$PATH:new/dir1/:dir2:/dir/path/new
This changes will be loaded after a reboot - to apply them immediatly after you changed it, save and close your file and type source $HOME/.bash_profile.
If you have any further questions, let me know - i'm going to edit my answer than.
By the way: There is a great Documentation on how to install Android-Platform on Windows machines. It can be found here, inside the Apache Cordova Docs -> Android - Shell-Tools Guide

Look for the local.properties file and add the correct path to your sdk sdk.dir=/home/somewhere/android-sdk/sdk
I would suggest to generate the project using cordova but build it using Android Studio, since you will probably want to tune one or two things on your android project anyway.
EDITED:
It seems you are on windows, so a quick way would be to set an Environment Variable called ANDROID_HOME pointing to the directory where you downloaded the android sdk as per the Cordova documentation
Either that or the steps stated on the documentation:
To modify the PATH environment on Windows 7:
Click on the Start menu in the lower-left corner of the desktop,
right-click on Computer, then select Properties.
Select Advanced System Settings in the column on the left.
In the resulting dialog box, press Environment Variables.
Select the PATH variable and press Edit.
Append the following to the PATH based on where you installed the SDK,
for example:
;C:\Development\adt-bundle\sdk\platform-tools;C:\Development\adt-bundle\sdk\tools

I was able to figure an answer out on my own. Coming from a complete beginner with no experience with bash profile, I was lost with your instructions (no offense). To fix this issue, learn how to edit your PATH environment variables. I used this tutorial (http://hathaway.cc/post/69201163472/how-to-edit-your-path-environment-variables-on-mac) which showed how to do it with textedit. After I learned how to edit my PATH variables, I added
export ANDROID_TOOLS="/Users/joshuaoconnor/Documents/sdk/tools"
export ANDROID_PLATFORM_TOOLS="/Users/joshuaoconnor/Documents/sdk/platform-tools"
to my BASH profile. Sithys and Logains answers did not work for me.

Related

Uiautomatorviewer is giving error "SWT folder '..\lib\location of your Java installation.' does not exist"

I have installed Android studio V 3.1.1
i am trying to launch UIautoamtorviewer.bat file from
C:\Users\panmishr\AppData\Local\Android\Sdk\tools\bin
however it always gives me error
SWT folder '..\framework\location of your Java installation.' does not exist.Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
below are list of env variables , which i have set
ANDROID_HOME: C:\Users\panmishr\AppData\Local\Android\Sdk
ANDROID_SWT:C:\Users\panmishr\AppData\Local\Android\Sdk\tools\lib\x86_64
JAVA_HOME :C:\Program Files\Java\jdk1.8.0_171
in Path Variable , i have included
C:\Users\panmishr\App;C:\Users\panmishr\AppData\Local\Android\Sdk\tools
C:\Users\panmishr\AppData\Local\Android\Sdk\platform-tools
My machine is 64 bit windows 7 .
Let me know, what i have missed.
I was able to resolve this with the help of sdkmanager.bat
Go to bin folder
C:\Users\panmishr\AppData\Local\Android\Sdk\tools\bin
run
`**sdkmanager.bat**`
it will give the correct error, like in my case JAVA_HOME path was
Set to old path in registry.
Run regedit
Search JAVA_HOME
Delete the old JAVA_HOME key and value.
log off the machine
run uiautomatorviewer.bat
This time it worked!!
In my case, I had the same problem because I was changed my JVM and I didnĀ“t restart the PC afther that. So the only think that I did was restart the computer and all the regedit files was update
I was able to fix the problem with below Steps:
set ANDROID_SWT = "C:\Users\xxxx\AppData\Local\Android\Sdk\tools\lib\x86_64"
{ The mentioned location is where swt.jar is located.}
Open CMD -> run uiautomatorviewer
It works !!
From my research Uiautomatorviewer works only with the version Java 8. So any version above 8 will not work. I had Java 17 installed and had to uninstall it.
You can download the the previous version of Java at this link from the official Oracle website:
https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html
Download the x86 version relative to you operating system. (For example I am using a Windows and downloaded: jdk-8u291-windows-i586.exe)
Now you have to configure the environment variables for "JAVA_PATH". To access this on Windows click on file explorer, right click, and select "properties".
On the right side of the windows form, select "Advanced system settings."
Click "Environment Variables" near the lower right corner of the window.
At this screen set "JAVA_HOME" to "C:\Program Files (x86)\Java\jdk1.8.0_291" as shown in the screenshot below.
From here, restart the computer and go the cmd and enter uiautomatorviewer.
This fixed the issue for me. Be sure to have your emulator turned on and remember to shut off the appium server when you are taking a screenshot of the emulator.

CMD acting weird. NOT DETECTING ANDROID_HOME Even If it is set

This is something weird,
first I set ANDROID_HOME in environment variable, and phonegap CLI was working properly, after that I installed android studio. It asked me to avoid ANDROID HOME path with spaces(I had space in path like: D:\Backup data\Android\sdk), then I removed space and updated the environment variables, both ANDROID_HOME AND PATH.
Now When I tried to run phonegap build android I get
The SDK Directory D:\Backup data\Android\sdk does not exist.
I tried setting it through cmd prompt as given here.
Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
But did not work either.
Also tried restarting the system and setting the variable in system variable section of environment variables.
Please guide me on this.
The new path is D:\Backupdata\Android\sdk, Backupdata is without space.
Found the answer,
for Phonegap android users,
the path is set in {Yourapp}\platforms\android, in the local.properties file.
sdk.dir=D\:\\Backupdata\\Android\\sdk
like this.
This was because first time I ran android studio the path was the old one with space, but after changing the path(without space), I never opened android studio, As this file is automatically generated by android studio.
Now it will be again overwritten by android studio next time I run it.
Hope this helps some one.

Linux Mint Android SDK Path Issue

I'm not able to include the android sdk to my PATH variable, so that I can use "android" from terminal.
I was following this tutorial to enable phonegap (which is my primary goal http://julianhigman.com/blog/2013/10/17/notes-on-setting-up-phonegap-on-ubuntu-for-android-app-development/)
First I took a look at the official android dev page
http://developer.android.com/sdk/installing/index.html?pkg=studio
It says:
"You may want to add android-studio/bin/ to your PATH environmental variable so that you can start Android Studio from any directory."
So I extended my .bashrc file with following lines
export PATH="/usr/local/android-sdk/android-studio/bin/:$PATH"
This points to the correct path as described in on the dev page.
Since this does not work I did some deeper research and found several threads which did not help either.
(Android command not found even PATH set)
Most recommend to do the following:
export PATH=${PATH}:/usr/local/android-sdk/tools
export PATH=${PATH}:/usr/local/android-sdk/platform-tools
The problem here is, that I dont have any folders named tools or platform tools?
I'm running on Linux mint 16.
If anyone could point me in the right direction, that would be great!
Update:
echo $PATH results to:
/usr/local/heroku/bin:/home/foo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/android-sdk/tools:/usr/local/android-sdk/platform-tools:/usr/local/android-sdk/android-studio/bin
But I added only this line
Added to enable android on the path
export PATH="/usr/local/android-sdk/android-studio/bin:$PATH"
Update
Had to install the packages after for android sdk and added them successfully to the .bashrc, now android is available.
Thanks in advance
Best

SDK Manager exec:114 java not found error in Ubuntu while running SDK manager

I have installed Java-ADT which is Android-SDK 64 bit version,installed jdk 64 bit version,installed jre 64 bit version,copied jre1.7.0_17 to eclipse folder and rename it to jre(after which I was able to run eclipse).
echo $PATH gives "/allSystemPaths:/pathToJDK:/PathToJDK/bin:/PathToJRE:/PathToJRE/bin:/PathToSDK/PlatformTools:/PathToSDK/tools"
echo $JAVA_HOME gives "/pathToJDK:/PathToJRE"
But when I run ANDROID SDK Manager still java not found error in android comes.I have searched a lot but not able to resolve it.
You can define a custom JVM in eclipse.ini, according to Eclipse documentation:
One of the most recommended options to use is to specify a specific
JVM for Eclipse to run on. Doing this ensures that you are absolutely
certain which JVM Eclipse will run in and insulates you from system
changes that can alter the "default" JVM for your system. Many a user
has been tripped up because they thought they knew what JVM would be
used by default, but they thought wrong. eclipse.ini lets you be
CERTAIN.
In order to do that, you need to know where is your Eclipse home or define it. In a console run:
$ echo $ECLIPSE_HOME
If you get a path skip next step. If you get nothing, that means you've to define one. On your home directory just edit .bashrc file and at the last file add:
ECLIPSE_HOME=$HOME/.eclipse
After this your ECLIPSE_HOME will be /home/YOUR_USER/.eclipse
Once you've a defined ECLIPSE_HOME, you need to create or edit a file named eclipse.ini inside of your ECLIPSE_HOME directory. Such file should have the following content:
-vm
/opt/sun-jdk-1.6.0.02/bin/java
Where /opt/sun-jdk-1.6.0.02/bin/java is the absolute path to java.

Can't get Android SDK Manager to open

Having searched here and elsewhere for answers to my problems, I'm still unable to fix this.
I've installed Eclipse, ADT Plugin, and the Android SDK. My problem is that the SDK Manager won't open, whether it is launched from Eclipse or directly. The command prompt window flashes up briefly, then closes.
I've tried several proposed solutions: Various configurations of my Path and JAVA_HOME variables, installation of the 32 and 64 bit versions of the JDK, running as Administrator, all with no success.
The different components are installed at these paths:
JDK - C:\Program Files\Java\jdk1.7.0_11
JRE - C:\Program Files\Java\jre7
SDK - C:\ADT\sdk
My JAVA_HOME is set to C:\Program Files\Java\jdk1.7.0_11
My Path includes C:\Program Files\Java\jdk1.7.0_11\bin at the beginning.
I've tried reinstalling the SDK and the installer correctly identifies the location of Java, and yet still it won't work.
Can anyone help me out with this? I'm practically tearing my hair out!
Open cmd,
go to android sdk folder,
in tools/lib/, edit find_java.bat,
you will see the lines like below, add black line to your file and save.
rem Check we have a valid Java.exe in the path. The return code will
rem be 0 if the command worked or 1 if the exec failed (program not
found). for /f %%a in ('%~dps0\find_java.exe -t') do set java_exe=%%a
this
set java_exe="C:\Program Files\Java\jdk1.7.0_11\bin\java.exe"
if not defined java_exe goto :CheckFailed
:SearchJavaW
rem Check if we can find a javaw.exe at the same location
than java.exe. rem If that doesn't work, just fall back on the
java.exe we just found. for /f %%a in ('%~dps0\find_java.exe -t -w')
do set javaw_exe=%%a if not exist %javaw_exe% set javaw_exe=%java_exe%
set javaw_exe="C:\Program Files\Java\jdk1.7.0_11\bin\java.exe"
i hope it helps
Answer by Talha is correct. Just adding that you might need to NOT include quotation marks in the black lines in his solution.
The following addition worked for me:
set java_exe=C:\Program Files\Java\jdk1.7.0_11\bin\java.exe
Found out what the cause of this problem was in my case: In the registry, there was a setting to have the CMD using UTF-8 (chcp=65001).
If I double click C:\Programmer\Android\SDK Manager.exe, I get the described symptoms.
If double click C:\Programmer\Android\sdk\tools\lib\SDK Manager.exe there is a hint:
A pop-up stating: Failed to execute tools\android.bat
Starting a CMD window in C:\Programmer\Android\sdk\tools and running android.bat, gave no output, even if editing the file and reming out the initial #echo off. Running the command chcp returned 65001.
So changing the codepage with chcp 850 and then running android.bat again, I got output, ending with the line: call lib\find_java.bat. This turned out to be the same problem. Each time a new CMD was spawned, the codepage changed to 65001
Fixed the problem by editing the following registry entry, deleting the value, and everything worked:
HKEY_LOCAL_MACHINE->SOFTWARE->Microsoft->Command Processor->AutoRun: #chcp 65001>nul
Having an empty value here, make the CMD using codepage 850, and the bat files begin to work again.
I am not quite sure what has made this change in the first place, but now I know the cure.
When extracting the adt-bundle-windows-x86_64-20131030.zip, three files were broken:
("sdk/tools/lib/httpcore-4.1.jar","sdk/tools/lib/find_java.exe","sdk/tools/lib/sdk-common.jar")
I don't know why but you can replace these files using old versions of android SDK e.g. android-sdktools_installer_r20.0.1-windows.exe. It worked for me.
After much searching.......and installing...re-intalling.....and changing the path of the android.bat as the answers above mentioned.....the final solution was: running Eclipse or the bat file or Android studio as administrator in windows 8 for the manager to open up!
check the md5 checksum for eclipse and android SDK.It might be an md5 check sum problem.
for calculating the md5 checksum of files u downloaded you can go to http://www.guidingtech.com/9800/what-is-md5-checksum-how-to-verify-it/
for correct md5 checksum :-
1. for eclipse go to link their official download site click on
downloaded package that u downloaded then go to check sum just match it with ur eclipse downloaded file.
2.for android sdk go to http://developer.android.com/sdk/index.html and click on download for other platformsand match the md5 checksum (f09aa4557bd1dc2703fde95dcdd6b92e).
i my case i downloaded all that stuff four times.
with regards
ajay
This could also happen if you haven't installed Java on your machine. I had a similar problem but after installing java it worked for me. You can download Java from https://www.java.com/en/download/help/download_options.xml.
Regards,
Abhi
Follow these steps and it help for me after a long time with all ways above not effect on windows7 64-bits, no need to have JAVA_HOME system variable or edit android.bat
Download Android Studio within Android SDK, Java JDK 64 bits and Java JRE x86
Install Java JRE first, then install Java JDK 64 bits, and the Android Studio last.
Now you start Android Studio first (64 bits version) it require to have JAVA_HOME setting to run JVM, just copy the jdk.x.x.x(version) folder (my PC: jdk1.8.0_25 from "C:\Program Files\Java\")folder to Android Studio folder and rename that folder (in Android Studio) to "jre" (jdk1.8.0_25 -> jre).
Now it work for me to open Android SDK Manager from anywhere, if you want to use eclipse (not official now) just copy the java jre.x.x.x(version) x86 folder (from where you install before) to Eclipse and rename to "jre". After coping, choose the Android SDK path in Eclipse to use, It works for both Android Studio and Eclipse.
Mind your antivirus if still refusing you (remove antivirus and install after you sure it not cause problem)!
cmd this "android.bat update sdk" ,this way can open "SDK Manager.exe"
note
1."D:\SDK\android-sdk-windows\tools" PATH in enviroment.
2.Replace sdk "tools" folder, this is site -> https://developer.android.com/studio/index.html, then select "Get just the command line tools".(new version deprecated "SDK Manager.exe")
this way worked for my Android Studio 2.3
3.and if "android.bat update sdk" can't work, see this video-> https://www.youtube.com/watch?v=FMLVY3PqPlc
I have tried all the above methods none of them worked.If you have already installed jdk-10 or any other then uninstall it and install jdk-8. If you created the path variables then immediately remove the 'JAVA_HOME' variable and also remove the java path from 'PATH' variable. Then install the jdk-8, and try to install sdk manager it works perfectly.
I found another solution, assuming you have Android Studio installed on your system:
Open Android Studio
Open settings (Control + Alt + S)
Locate "Android SDK" setting (Appearance & Behavior -> System Settings)
On the right side, you'll have the SDK related tabs
Try This >
Go to sdk folder
Right Click on Sdk Manager then Run as A administrator .
It will open sdk manger and your problem will solve

Categories

Resources