settings.gradle 中的环境变量不适用于 Android Studio [英] Environment variable in settings.gradle not working with Android Studio

查看:31
本文介绍了settings.gradle 中的环境变量不适用于 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:

/projects_home/projects/app_root
   |--app/
   |   |--build.gradle
   |--build.gradle
   |--settings.gradle

/libraries_home/libraries
   |--libA
       |--build.gradle

在我的 settings.gradle 文件中,我可以使用 projectDir 属性设置库项目的绝对路径.这在控制台和 Android Studio 中都可以正常工作.

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.

但如果我尝试使用环境变量,它会停止与 Android Studio 一起工作.上面示例的 settings.gradle 将如下所示:

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')

如果我使用控制台中的 graddle 包装器进行构建,它仍然有效.但 AS 停止工作,出现以下错误消息:

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.

因此,我猜 AS 以某种方式无法访问使用我的 ~/.bashrc 设置的环境变量

Therefore I guess that AS is somehow not be able to access the environment variables set with my ~/.bashrc

你们中有人知道如何让 AS 了解我的环境吗?

Does somebody of you maybe know a way how I can make AS aware of my environment?

推荐答案

Android Studio 不读取环境变量,因此这种方法不起作用.此外,在 settings.gradle 中使用 projectDir 方案可能会导致问题.Android Studio 有一个限制,即它的所有模块都需要位于项目根目录下.如果您有在多个项目中使用的库并且它们不能放在单个项目根目录下,最好的建议是让它们将 JAR 或 AAR 发布到单个项目可以获取的本地 Maven 存储库.

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.

这篇关于settings.gradle 中的环境变量不适用于 Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆