ckihm ckihm - 11 months ago 59
Android Question

Environment variable in settings.gradle not working with Android Studio

I do have a multi-module project with a library project in a different root path. As illustration you can imagine something like this:

| |--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?

Answer Source

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.