I do have a multi-module project with a library project in a different root path. As illustration you can imagine something like this:
/projects_home/projects/app_root
|--app/
| |--build.gradle
|--build.gradle
|--settings.gradle
/libraries_home/libraries
|--libA
|--build.gradle
In my settings.gradle file I am able to set the absolute path to the library project utilizing the projectDir attribute. This works just fine within the console as well as with Android Studio.
But if I try to use an environment variable it stops working with Android Studio. The settings.gradle for the example above would look like this:
include ':app'
include ':libA'
project(':libA').projectDir = new File("$System.env.LIB_ROOT", '/libraries/libA')
If I build with the graddle wrapper from the console, it still works. But AS stops working with the following error msg:
Gradle 'app' project refresh failed:
Configuration with name 'default' not found.
If I unset the environment variable, the build on console fails with the same msg:
* What went wrong:
A problem occurred configuring project ':app'.
> Configuration with name 'default' not found.
Therefore I guess that AS is somehow not be able to access the environment variables set with my ~/.bashrc
Does somebody of you maybe know a way how I can make AS aware of my environment?
Android Studio does read the environment variables. You can prove it by launching Android Studio from the shell in which those env. variables being specified instead of from X-window dash board.
The reason you did not have those variables is the X-window environment you were using did not read $HOME/.bashrc which contained those variables. This makes sense because bashrc is for Bash not X.
Assuming you are using GNOME or Unity, to launch Android Studio with those environment variables being specified, just modify the .desktop file of Android Studio (e.g. ~/.local/share/applications/android-studio.desktop):
Find this line:
Exec="/home/username/tools/android/android-studio/bin/studio.sh" %f
Change it to:
Exec=env LIB_ROOT=/libraries_home "/home/username/tools/android/android-studio/bin/studio.sh" %f
Note:
This modification just prepend env LIB_ROOT=/libraries_home to the original command. You must replace username with your own user name.
Update
If you have any questions, please leave a comment instead of editing the answer directly.
On Macs, Android Studio does not read environment variables for use in Gradle apparently. I believe this is the cause for confusion in the answers here - maybe it does on Windows.
In order to get Android Studio to read environment variables, I run the application from the command line:
> /Applications/Android\ Studio.app/Contents/MacOS/studio
The other answers here offer solutions other than using environment variables. For my situation, I'm using a library I didn't write that requires the use of an environment variable, and I'd rather not edit their code so it's easier to update later.
EDIT: And, I have a dock icon to launch Android Studio this way:
OSX: Add Dock icon for dedicated Terminal command explains how.
Android Studio doesn't read environment variables, so this approach won't work. Also, using the projectDir scheme in settings.gradle will probably cause problems. Android Studio has a limitation that all of its modules need to be located underneath the project root. If you have libraries that are used in multiple projects and they can't be placed under a single project root, the best advice is to have them publish JARs or AARs to a local Maven repository that individual projects can pick up.
Despite the answer from Scott Barta is correct, I realized there is a way to solve my problem and wan't to share this in case somebody else has the same requirement.
I am now using the gradle.properties file do define and use gradle properties instead of system properties. The documentation of this feature can be fined in the user guide
The solution to my original question now looks like this:
$USER_HOME/.gradle/gradle.properties:
LIB_ROOT=/libraries_home
The settings.gradle file has to be modified to use the gradle property instead of the system property:
include ':app'
include ':libA'
project(':libA').projectDir = new File(LIB_ROOT, '/libraries/libA')
This works fine for me, headless as well as with AS.
Some more words regarding the fact that I am working with modules which are not placed underneath one project root. Till now it looks like AS is not complaining about this. But I just started working with this structure and it may be that I will run into problems later. What I like about this is the more flat representation in AS which is more like I am used to have it with Eclipse.
What is also described in the user guide, is to set system properties with the gradle.properties file. I tried this also, but I did run into the same problems with AS using environment variables.
It works for me with the following steps:
Set your variable in Windows
Reboot
reach it in gradle build: System.env.MYVARIABLE
I faced the same issue in apple laptop after the Android Studio Bumblebee update. This seems to be happening due to some permission issue with the Android Studio.
The workaround is to add missing flag:
chmod +x /Applications/Android\ Studio.app/Contents/bin/printenv
You can check this issue tracker for more details.
You can set environment variable by appending:
-DYOUR_VARIABLE=variable_value
to ~/Library/Preferences/AndroidStudioX.X/studio.vmoptions that you can open by selecting Help -> Edit Custom VM Options... from Android Studio menu.
And then you can use it like:
System.env.YOUR_VARIABLE
in build.gradle or settings.gradle.
MAC OS Update
I confirm that I have Environmental Variables working on Mac OS Catalina
You just need to set it in the shell you are using. I was using zsh, and was trying to set ~/.bash_profile, so it wasn't working.
Example:
ZSH Profile
Related
I downloaded the latest version of Android studio and created a new project, but it seems that I can't get it to work since the Gradle Daemon is failing because my windows user has a comma ' . My username also has a space, but I guess that I shall see if I will get another error when I reach there.
Any settings that I can do to bypass this problem, without changing my user name?
You could try various hacky things like setting your GRADLE_USER_HOME and TEMP environment variables to folders outside your user space (e.g. C:\gradle & C:\temp).
However, you're going to be fighting against Gradle / Android / the entire build process now and forever! I'd really really recommend instead using a name without special characters. If this isn't possible, perhaps a new user with a simple name would be a quick fix.
After some searching, I had an idea and I found a possible solution:
The solution is a mix of these 2 questions:
Set gradle temporary directory to SSD
Android Studio missing essential plugin org.jetbrains.android
1. Change Gradle temp files to another directory
Create a new folder ex: D:\some\dir\
Go to System Properties and edit the Envitonment Variables.
Add GRADLE_OPTS with -Djava.io.tmpdir=D:\some\dir\
Add GRADLE_USER_HOME with D:\some\dir\
2. Remove disabled_plugins.txt file
Go to the following path and delete the file:
C:\Users\YourUserName\AppData\Roaming\Google\AndroidStudioVersion\disabled_plugins.txt
3. Re-create the project
I'm using Netbeans 8.1, with gluon and nbandroid plugins, on Windows 8.1, and when I create a gluon basic project i can't run on Android platform, the error are about ANDROID_HOME, in the last two days I have searched a lot about it but all the tries I have made don't help.
Here is the error:
Caused by: org.gradle.internal.exceptions.LocationAwareException: ANDROID_HOME not specified. Either set it as a gradle property, a system environment variable or directly in your build.gradle by setting the extension jfxmobile.android.androidSdk.
Caused by: org.gradle.api.GradleException: ANDROID_HOME not specified. Either set it as a gradle property, a system environment variable or directly in your build.gradle by setting the extension jfxmobile.android.androidSdk.
I tried the sample project from gluon, and the error still appears, but if I create an Android project (nbandroid, not gluon) and run it, everything is ok.
I see same difference from other questions on the project, when I create a gluon basic project automatically a Android project is created, but i don't see that on a lot of movies i watch on Youtube.
Can anyone help me, please? If more data is needed, I can upload it.
You can have a look at the JavaFXPorts documentation on the prerequisites to get started.
There are several options on how to set ANDROID_HOME. Basically:
Define the androidSdk property under jfxmobile.android in build.gradle:
jfxmobile {
android {
manifest = 'src/android/AndroidManifest.xml'
androidSdk = 'C:/<path to>/Android/sdk'
}
}
Or create a file named grade.properties, and place it in your local gradle folder (C:/Users/<user>/.gradle), adding this property:
ANDROID_HOME=C:/<path to>/Android/sdk
If you use the second option, you won't need to take care of adding it all the time on new projects.
Also you will find this local file added on your NetBeans projects, in a Gradle Home folder:
One developer on my team has some setting in Android Studio that replaces the distributionUrl entry in gradle/wrapper/gradle-wrapper.properties to use the gradle-###-all.zip, while my Android Studio changes it back to gradle-###-bin.zip.
Basically, my diff always looks like:
-distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
This is annoying. What setting is it, and how do I change it?
gradle-1.12-all.zip file will have binaries, sources, and documentation.
gradle-1.12-bin.zip will have only binaries(That should be enough as you don't need any samples/docs)
If you want to know about gradle wrapper, please check this
http://www.gradle.org/docs/current/userguide/gradle_wrapper.html
If you and the other developer want a uniform experience, place this code in your build.gradle file
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
This will make ./gradlew wrapper --gradle-version 5.6 automatically append -all instead of -bin
For build.gradle.kts:
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
Like #San said, -all will have binaries, sources, and documentation, while -bin will just have the binaries.
From what I've seen Android Studio recommends to use gradle-*-all.zip and even provides a "quick fix" to change that. On the other hand, the command ./gradlew wrapper sets up the wrapper using gradle-*-bin.zip, overwriting the previous setting. Make sure nobody is calling "./gradlew wrapper" automatically.
The difference is that the -bin version contains only the runtime and no sample code and documentation. 1
It actually makes sense to go for the -bin version: it is smaller and you're unlikely to need the -all version unless you're debugging Gradle scripts. For this reason, the lint warning to go for the -all version has been removed. Also, new projects are generated with the -bin version by default.
There is a ticket to let IntelliJ download the sources when you need them (after which there really isn't a reason for the -all version), but it hasn't been implemented yet.
I need help. I'm trying to install and configure OpenCV 2.4.7 library in my computer (Ubuntu 12.04). After run OpenCV samples appears those errors in my Console:
Cannot run program "/NDK-build": Unknown reason
Error: Program "/NDK-build" not found in PATH=[/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games]
I've seen numerous tutorials and nothing worked. I ask you to be very specific since I am "new" programming and also because my mother tongue is not English (I have some difficulties). Thank you!
Easiest Method which worked for me is.
Goto the Project Properties
Click on C/C++ Build (An other list will open)
Click on the Environment from the list
Now click on Add
Here you have to Put 2 values
Put Name as NDKROOT
In Value put PATH TO THE NDK FOLDER
You are done :)
Same case happened with me (when my NDK location was already set), so changing to original Android Builder removed my problem for doing so simply go to project properties, C/C++ Build | Tool Chain Editor and select Android Builder as current builder.
Do you have android-ndk installed? If yes, add path to ndk-build to your path.
e.g:
export PATH=$PATH:~/android-ndk/bin
Add the ndk-build to your path
Follow this guide
http://my.safaribooksonline.com/book/programming/android/9781849691529/setting-up-your-environment/ch01lvl1sec18
this is a frequent issue with openCV for Android. It stems from having the incorrect build target, which creates an error within the library for the Video.java file. After getting that patched up, you can import sample projects. Although, after fixing that, you may not be able to see the C/C++ Build node under project preferences. There's a fix for that on the second link. However, if under project preferences you can see C/C++ Build, make sure the path reads: "${NDKROOT}/ndk-build" Finally, it will be looking for NDKROOT,which is undeclared. The third link will direct you on how to do this, it's very simple. ALSO, make sure if your on MAC or LINUX to remove the .cmd from the end of NDK-BUILD. Good Luck!
Video.java issue:
http://answers.opencv.org/question/8266/opencv-library-244-on-eclipse-gives-error/
C++ Build/General Missing from Project Preferences:
http://stackoverflow.com/questions/16953548/eclipse-missing-c-c-build-and-general-from-project-properties
Now, make sure you add NDK root to the build varialbles so you can find it:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Ftasks%2Fcdt_t_add_build_var.htm`
On Windows 7 (64 bit) with the Android SDK working perfectly with Eclipse - my first android application, using the first "Hello World" sample (found here - http://docs.xamarin.com/android/getting_started/hello_world - from Xamarin)
fails with the error "the OutputPath property who is not set for project NameProject.csproj".
I have tried re-runing the installation program from Xamarin and this error still occurs.
Could someone please suggest what may be causing this problem?
Thanks a lot.
the exact error:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(9,9):
Error: The OutputPath property is not set for project 'helloWorld3.csproj'.
Please check to make sure that you have specified a valid combination of
Configuration and Platform for this project.
Configuration='Debug'
Platform='BPC'.
This error may also appear if some other project is trying to follow a
project-to-project reference to this project, this project has been
unloaded or is not included in the solution, and the referencing project
does not build using the same or an equivalent Configuration or Platform.
(helloWorld3)
I think we've seen this before. Your system manufacturer installed an environment variable called Platform onto your system. This breaks all msbuild based stuff, since msbuild automatically imports that as $(Platform), conflicting with the real $(Platform) that msbuild uses to compile.
Try removing the environment variable and try again.