I am running Gradle script. At the beginning I print PATH environment variable:
println System.getenv( 'PATH' )
The output is:
/usr/bin:/bin:/usr/sbin:/sbin
But the real PATH environment variable is (printed from terminal):
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sh........
Question is, why that PATH env variable do not math in Gradle script and in terminal?
Thing is, that I am building Android, which use Gradle as build system. And I have c++ code, which is build by CMake. And in CMake i run some python scripts, which executes some external commands. But when Gradle changes PATH variable, those commands are not found and I am getting an error. It is not an option to use full path, when executing those commands, like:
/usr/local/bin/my_mega_command
When I run CMake or python script directly, then everything works as expected.
Android Studio does not pass its environment down to the Gradle daemon that it spawns. Usually, we see this in the form of missing custom environment variables, but apparently it affects PATH changes as well.
I had the exact same issue where running gradle tasks from the Terminal (inside or outside Android Studio) would correctly take the PATH set in the environment (i.e. via .zprofile or any of the other possible methods), but not when running via the Gradle commands from the Android Studio Toolbar. What ended up working for me was changing the JDK version used from the one that came with Android Studio (JDK 11) to JDK 1.8, and suddenly it worked. I don't know why this changes anything, but now the PATH is taken from the environment set in the system and everything works.
Related
I have set an environment variable ANDROID_HOME, which points to my android SDK location. However, every time I open my project in Android Studio it places local.properties file to the root of my project and copies my SDK location from ANDROID_HOME to this file. I want Android Studio use ANDROID_HOME directly, without generating local.properties.
Why? I'm on Windows 10 and I use Bash for Windows. I want to run command line using Bash while running Android Studio from Windows. For this I need two ANDROID_HOME environment variables, one for Windows, one for Bash. This is because although they point to the same (windows) android SDK the format is different, for Windows it is C:\Users\me\Android SDK while for Bash it's /mnt/c/Users/me/Android SDK. When Android Studio creates local.properties with windows path Bash becomes broken since apparently local.properties takes advantage over ANDROID_HOME, so I have to delete it manually.
You might find this article useful:
Posix path conversion (mingw.org)
The gradle android plugin "Application" extension
(your regular gradle-android interface) has a property
sdkDirectory. Perhaps this can override it? I can't check.
I think there is a configuration switch for bash on Windows to parse path separators Windows-like, can't seem to find it, it is buried deep inside MinGW or MSYS docs I think.
Last resort - git Hooks. Read the ProGit book chapter on Hooks.
The Android will generate this file always when gradle sync it. But if you delete it and define ANDROID_HOME and ANDROID_NDK_HOME environment variables, every time that generates it will read ANDROID_HOME and ANDROID_NDK_HOME.
If you want to build your project in many computers with different home folders, just keep the local.properties outside the source version control.
As described here in the Android Studio docs, one can build an Android app from the command line with the gradle wrapper generated by Android Studio. The command line window in Android Studio shows exactly this, i.e. a call to gradlew assembleDebug (or a similar task). However starting a terminal on macOS and calling the gradle wrapper with that exact call sometimes yields other results, i.e. either one is able to build from Android Studio, or the command line, or both (which is ideal, but unfortunately not always true).
Who can explain what other settings the Android Studio IDE sets for their environment and where to find them, how to reproduce these settings easily in a CI environment (e.g. Jenkins, Bamboo, ...) and how one would consistently store these settings in a VCS along an Android project.
In the root of the project you have gradlew.bat, which is how you can run it in the first place. If you open this file, you see the code for building and everything else Gradle does.
Whether you build from the command line or ANdroid Studio, the gradlew.bat file is used. So building and other stuff you do with the gradlew command all use the same file whether it is from the command line or Android Studio's integrated tools.
You can open the file(s, there's gradlew and gradlew.bat in the project root) and see how it works if you wanted too, though these files are usually automatically generated by Android Studio (it is possible to make your own config as well, though there's rarely a need for that). And for including in vcs, make sure the files aren't listed in .gitnore (or whatever vcs ignore extension you have)
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
I've read this: Cordova and setting Android using command line
and that How to add android to cordova platform? PATH error? and generally speaking whole documentation. I've added both 'platform-tool' and 'tool' paths, installed android 4.4 and I'm still getting the error from the tittle when I'm trying cordova platform add android to my current project ( in cmd and in netbeans ).
The only thing I haven't done is adding java and ant to path. I was trying with ;%JAVA_HOME%\bin;%ANT_HOME%\bin but still those commands aren't recognizable.
What else can I do?
EDIT:
I've added java and ant to PATH. This is what I get in cmd:
C:\xampp\htdocs\mobile_maps>cordova platform add android
[Error: The command `android` failed. Make sure you have the latest Android SDK
installed, and the `android` command (inside the tools/ folder) added to your pa
th. Output: ]
Second EDIT:
i also get 'xcopy' is not recognized as an internal or external command even though I've added %SystemRoot%\System32; %SystemRoot%; %SystemRoot%\System32\wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0 . I really don't know what else I can do..
usually this happens when:
1. Java is not installed
2. Java is not exported (no JAVA_HOME env variable) or paths are wrong
3. only 64bit version of Java is installed
to fix install 32bit support on your system.
and (as comments below) relog in Windows to environment changes take effect.
I'm trying to build my android app via commandline (batch file to be specific). I'm working on a phonegap/cordova app and I find it to be a bit of an overkill to use Eclipse only for compiling.
If I try it via commandline it works. But if I run it in a batch file it looks like ANT is using JRE instead of JDK??
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre7\lib\tools.jar
If you want to use javac in ant then you need tools.jar to work it properly. You can find this answer on apache ant site (When you need JDK functionality (such as for the javac task or the rmic task), then tools.jar must be added. The scripts supplied with Ant, in the bin directory, will add the required JDK classes automatically, if the JAVA_HOME environment variable is set.).
Not sure why this happens. But you would usually find tools.jar in C:\ProgramFiles\Java\JDK\lib
Copying that to the C:\ProgramFiles\Java\jre\lib folder would make it work without any change to the JAVA_HOME