In the beginning..
I know that this question has been asked way too many times and.. I checked all ansers on SO. Tried every combination and every solution I found but nothing has worked for me so far.
The problem
I've succesfully installed cordova downloading it from the official site and I've been following the Guide.
I've added wp8 platform succesfully first. Then I tried to add android as well.
After executing the command cordova platform add android, I got the following error.
Error: executing command 'ant', make sure you have ant installed and added to your path.
Here's a screenshot with more details:
My efforts
I've installed ANT, the last Java JDK and added all necessary Enviroment Variables to my System.
ANT and JAVA both gets executed fine from any source path.
ant -version outputs
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
java -version outputs
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
Enviroment Variables
I've set up every necessary variable. From ANT_HOME to PATH. Everything is as it should be
ANT_HOME: C:\Program Files\Ant
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_05
ANDROID_HOME: C:\Users\Kevin\Desktop\Cellulare\Development\sdk
PATH: %JAVA_HOME%\bin;%ANT_HOME%\bin;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;
As everyone can see, I've also added android platform-tools and tools to my PATH. Same thing for Ant and Java (\bin dirs).
Needless to say but every path is correct.
Having this things said, Why this still doesn't work? I've also restarted my PC as well but with no results.
Solution
Thanks to Kerri Shotts.
My problems were from those spaces in my paths.
So I changed C:\Program Files\... to C:\Progra~1\....
IMPORTANT!
I also noticed there were 2 □ characters in my strings. Like this ..\C□□ellulare\... They probably came from a wrong copy-paste format. After fixing these things everything worked!
Due to the nature of languages, whitespaces are executed in some whilst ignored in others.
Utilizing a file name such as "Program(whitespace)Files" does produce errors when compiling from \bin directories.
Next time you declare an environmental variable, be sure that your folder does not contain any whitespaces or gaps between the various names.
FYI: camelCase scripts where introduced tow work around this concept.
Thanks.
Related
I would like to enjoy SDK Android tools without downloading and installing Android Studio on my Windows 7 64. I have Java version:
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
It is obviously possible as explained on the official page:
https://developer.android.com/studio/index.html#command-tools
So I download and extract this zip 'commandlinetools-win-6200805_latest.zip' to my folder:
C:\Program Files\Android
And I get a subfolder 'tools' inside my folder :
C:\Program Files\Android\tools
which contain other subfolders 'bin' and 'lib'.
When I run in command line 'sdkmanager' (located in 'bin' folder), I get this error message:
Error: Unable to find or load the main class Files\Android\tools\bin\\
!!! The message is in French and I translated it !!! So please forgive me if it is not 100% accurate. I can't reproduce the error message in English as my OS is in French.
There are no guidelines or README or tutorial about the process to download and install this Android SDK package. I guess because it supposes to work.
I've seen a lot of issues like this but these issues are coming from different scenarios for other purposes.
I couldn't find a solution to my problem.
Do you have any idea what am I missing here?
After some investigation and tests, I found the answer. I will post here the guidelines for some newbie who would like to enjoy SDK Android without Studio on his machine.
You must create a folder 'Android\cmdline-tools' in
C:\Users\your_username\AppData\Local\Android\cmdline-tools
Then you unzip the ZIP files in this folder.
Then you will see a folder 'tools' inside your folder
'cmdlines-tools'. You rename it 'latest'.
You add environment variable
ANDROID_HOME=C:\Users\\AppData\Roaming\Android\cmdline-tools\latest
You add to PATH environment variable this path : %ANDROID%\bin
Et voilà!
Don't forget to restart your command line to enjoy the new environment variable or to reboot your computer if necessary.
I have no idea why it must be located in this folder, why to rename the folder tools in the latest... But it works! If you're an expert, feel free to explain in comments or in new answer.
• I have used the command
xamarin-component.exe package C:\cmp\AndroidComponent\component
for creating Xamarin component.While building the Sample android project, it is showing the below error. (I have used the command xamarin-component.exe package C:\cmp\AndroidComponent\component -verbose to display the error message in detail).
Error message:
C:\Program Files
(x86)\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.targets(155,2):
error MSB3644: The reference assemblies for framework
"MonoAndroid,Version=v1.0" were not found. To resolve this, install
the SDK or Targeting Pack for this framework version or retarget your
application to a version of the framework for which you have the SDK
or Targeting Pack installed. Note that assemblies will be resolved
from the Global Assembly Cache (GAC) and will be used in place of
reference assemblies. Therefore your assembly may not be correctly
targeted for the framework you intend.
[C:\cmp\AndroidComponent\component\samples\App17\VidyoClientAndroid\VidyoClientAndroid.csproj]
Note:
I am able to create a Xamarin component for iOS source code successfully.
• While creating the Xamarin component for Android source code, internally msbuild.exe is getting called from 64 bit folder(C:\Program Files (x86)\MSBuild\14.0\bin**amd64**\msbuild.exe "/p:Configuration=Release" "C:\cmp\AndroidComponent\component\samples\App17\App17.sln"...).
• Build is successful when msbuild.exe is called from path: “C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe”(32 bit) explicitly while building the android project explicity.
We ran into the same issue; you were close to the right answer, and the forums had the correct one.
First lets look at the portion of code that is erroring (Xamarin.Android.Common.targets; in the newer versions of Xamarin this code is much further down):
<Target Name="_GetReferenceAssemblyPaths">
<GetReferenceAssemblyPaths
TargetFrameworkMoniker="$(TargetFrameworkIdentifier),Version=v1.0"
RootPath="$(TargetFrameworkRootPath)">
<Output TaskParameter="ReferenceAssemblyPaths" PropertyName="_XATargetFrameworkDirectories" />
</GetReferenceAssemblyPaths>
The most important part here is the
$(TargetFrameworkRootPath)
When NuGet is ran via the command line we see that it is using the 64bit MSBuild Executable:
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin\amd64'.
(You correctly identified this yourself above) but just to be clear for anyone following along.
When you use the 64bit version of MSBuild $(TargetFrameworkRootPath) gets defined as C:\Program Files\Reference Assemblies\Microsoft\Framework However Xamarin does not install any of the Framework Utilities to that directory; instead everything lives in the x86 version here C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework
When you read online a ton of people get this problem solved by installing Visual Studio 2017; but that is a red-herring it only works because it causes NuGet to use MSBuild 15 which ships with Visual Studio 2017 which apparently is not affected by this bug.
There are a few ways to fix this issue:
Tell NuGet to use the x86 MSBuild when you Restore using the optional -MSBuildPath argument as described here How Can I Tell NuGet What MSBuild Executable to Use?
Upgrade to Visual Studio 2017 to get MSBuild 15
Define $(TargetFrameworkRootPath) to be C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework; this can be done however you please, the biggest hammer is to set it as an environment variable in the environment prior to execution. Note this will probably cause a bunch of unintended side-affects if you're not careful. <- DON'T DO THIS, Even as suggested in the forms.
I have read all the questions for the same problems and I have tried everything but nothing is working for me when I try to add android platform for cordova.
c:\Apps\fapp>cordova platform add android
Creating android project...
C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node_modules\q\q.js:126
throw e;
^
Error: An error occurred while listing Android targets
at C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\lib\check_reqs.js:
87:29
at _rejected (C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node_mo
dules\q\q.js:808:24)
at C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node_modules\q\q.j
s:834:30
at Promise.when (C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node
_modules\q\q.js:1079:31)
at Promise.promise.promiseDispatch (C:\Users\Andrej\.cordova\lib\android\cor
dova\3.4.0\bin\node_modules\q\q.js:752:41)
at C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node_modules\q\q.j
s:574:44
at flush (C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node_module
s\q\q.js:108:17)
at process._tickCallback (node.js:415:13)
Error: cmd: Command failed with exit code 8
at ChildProcess.whenDone (C:\Users\Andrej\AppData\Roaming\npm\node_modules\c
ordova\src\superspawn.js:112: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)
Project is created using cordova create fapp com.fapp Fapp
System is windows 8
ANT, JAVA (JDK 1.7.0_51 and JRE7), Android SDKs are installed from (17-19.0.3) and Android APIs (17-19)
All environment variables for JAVA, ANDROID and ANT are set as well as path to bin for all of them into Path variable.
I really tried everything but keeps throwing this problem.
EDIT:
Answer here did not help:
cordova ubuntu: An error occurred while listing Android targets
Permissions are set to Everyone full control and same issue
FINAL SOLUTION
Finally I re-installed JDK and Android SDK and now everything works even it is still mystery to me.
I had the same issue and solved it by setting the following environment variables:
%JAVA_HOME% points to the root of your java installation (not the bin directory). In my computer it is: C:\Program Files\Java\jdk1.8.0. To test that it is configured correctly, open a new terminal and type javac. It should run the java compiler and shouldn't complain that it doesn't know the command. Please note that environment variables are only set when opening a new terminal (at least on windows) so every time you change something you have to open a new terminal.
%ANT_HOME% point to the root of where you've installed Apache ant. In my computer it is: C:\Users\User\apache-ant-1.9.3. Test it by running the ant command. It shouldn't complain that the ant command is unknown to your machine. Remember to open a new terminal after setting the path and then try running ant.
%ANDROID_HOME% points to where you have installed your android SDK. For example: C:\Users\User\android\sdk. Then try typing emulator to make sure it is installed correctly.
When all of these variables are set, you can use them in the PATH environment variable :
%PATH% contains the following entries: %ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin
On windows 8 you can configure path and variables by right clicking on the start button, choosing system, and then advanced system settings and clicking on environment variables button. Remember to define the above environment variables above PATH. I defined everything in the user variables and it works just fine.
-Possible solution for those who encounter this error
I had this error and it did relate to the path variables. I thought I had everything set correctly, but I was missing a portion.
First check by typing the command android into command line. If the SDK isn't opened you have not set the variables and/or path correctly.
You should have 3 (or 4 if you have separate android ones) variables.
ANT_HOME, JAVA_HOME and ANDROID_HOME
ANDROID_HOME should point to the sdk. If you (like I did) downloaded the bundle which includes eclipse, you need to have this variable point to the sdk folder inside the android bundle folder, not the android bundle folder itself (eg. C:\Dev\adt-bundle-windows\sdk)
You need to add %ANDROID_HOME%\tools and %ANDROID_HOME%\platform-tools to your path. Along with the link to the ANT bin folder and jdk bin.
I strongly urge you to triple check that all variables are correctly set AND that all four parts are added to the path.
Please Refer the Question
An error occurred while listing Android targets
and the Link
developer.android.com/tools/devices/managing-avds-cmdline.html
Most probably the path variable pointing to this android was wrong.
I had used %ANDROID_HOME% as variable and scaled the same to path variables %ANDROID_HOME%\SDK\TOOLS. This method doesn't work. Experimentally resolved by directly pointing to the Tools and Platform Tools.
Just based on what I did and it worked for me. Hope You get the Issue resolved.
I had the same issue with version 3.5.0.
The problem is, that the error message from the script check_reqs located in C:\Users\{yourUserName}\.cordova\lib\android\cordova\3.5.0\bin, is not forwarded correctly.
I run the mentioned script manually and got the following error message:
[Error: Please install Android target 19 (the Android newest SDK). Make sure you have the latest Android tools installed as well. Run "android" from your command-line to install/update any missing SDKs or tools.]
So basically to solve this issue you have to install the latest Android SDK.
This link http://spring.io/guides/gs/android/ + running cmd as an administrator solved that issue for me.
This confirms Michael Brooks' assumption that this issue has to do with permissions settings on the Windows OS. https://github.com/phonegap/phonegap-cli/issues/77
Trying to use Phonegap in Eclipse on windows 8. I've created a project at C:\Development\HelloWorld. In the command line, when I type:
phonegap local build android
I get the following error:
An error occurred during creation of android sub-project. ERROR : executing command 'ant', make sure you have ant installed and added to your path.
My PATH:
C:\Program Files\nodejs\;C:\Development\adt-bundle\sdk\platform-tools;C:\Development\adt-bundle\sdk\tools;%JAVA_HOME%\bin;%ANT_HOME%\bin;
Whats going wrong? I have downloaded Ant into my Development folder and all other necessary downloads are downloaded as well. Any help would be appreciated.
I was following Phonegap's platform guide for Android and I kept getting the above error. The directions on the guide were a little confusing. I went back to check what I had installed and found some configuration errors.
Under Environment Variables, I created new ANDROID_HOME, ANT_HOME, and JAVA_HOME system variables with the respective physical file paths as the value. This part may be overkill, but I was trying to cover my bases and I have noticed no significant issues with it so far.
Example:
Variable: ANDROID_HOME Value: C:\Development\adt-bundle\sdk
Variable: ANT_HOME Value: C:\Development\apache-ant-1.9.2
Variable: JAVA_HOME Value: C:\Program Files\Java\jdk1.6.0_45
Next I added the following values to the Path system variable in Environment Variables:
%JAVA_HOME%\bin;%ANT_HOME%\bin;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;
After making these changes and continuing to follow the guide, everything worked like it should. It boiled down to not having my system variables set to the correct physical file path.
Check android in cmd, if it says: 'xcopy' was not recognized.
then add to your path:
%SystemRoot%\system32; %SystemRoot%; %SystemRoot%\System32\Wbem;
Just as a extra note to Rex_C's answer: Be sure to reference the Java Development Kit (JDK) and not the Java Runtime Environment (JRE) in the JAVA_HOME variable. This will prevent the
Command failed to execute : ant jar
error when running phonegap->android.
I am currently trying to compile a qt project to run on an android tablet and the build process works as expected, but when I try to deploy it, it quits saying it can't find the javac compiler because JAVA_HOME is set to the place where the JRE resides.
I have already tried adding JAVA_HOME to the build environment in Qt Creator, then in the/etc/profile file and finally outputting the JAVA_HOME variable from the script that starts ant and they all point to the correct path.
I have also tried to grep through all the files for the JRE path string literal, but this didn't yield any results.
You'd want to install the JDK. Just the JRE won't be enough.
This is because only the JDK has the Java compiler, JRE is just the Java Runtime Environment.
After a few unsuccessful attempts I found that it was in fact looking for the tools.jar file that got moved to another location in openjdk 7, even though the error messages were referring to JAVA_HOME.
I installed openjdk 6 and it works now