将项目包含为具有相对路径的模块 [英] Include projects as modules with relative path

查看:132
本文介绍了将项目包含为具有相对路径的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将外部项目作为模块包含在我的应用程序中,但我希望它们的路径是相对的.

I am trying to include external projects as modules in my app, but I want their path to be relative.

我尝试过以下操作:

settings.gradle

include ':MyLibrary1'
project(':MyLibrary1').projectDir = new File(settingsDir, '..\\Library\\MyLibrary1')
include ':MyLibrary2'
project(':MyLibrary2').projectDir = new File(settingsDir, '..\\Library\\MyLibrary2')
include ':MyLibrary3'
project(':MyLibrary3').projectDir = new File(settingsDir, '..\\Library\\MyLibrary3')
include ':MyLibrary4'
project(':MyLibrary4').projectDir = new File(settingsDir, '..\\Library\\MyLibrary4')

build.gradle

compile project(path:  ':MyLibrary1')
compile project(path:  ':MyLibrary2')
compile project(path:  ':MyLibrary3')
compile project(path:  ':MyLibrary4')

但我收到此错误:Error:Configuration with name 'default' not found.

推荐答案

错误:找不到名称为默认"的配置

Error:Configuration with name 'default' not found

当gradle寻找模块build.gradle却找不到它时,就会发生这种情况.

It happens when gradle is looking for a module build.gradle and it can't find it.

确保将引用到库中的模块而不是根文件夹.

MyLibrary1
|--settings.gradle
|--build.gradle
|--module
|----build.gradle

如果您具有这样的结构,则必须引用\\Library\\MyLibrary1\module而不是\\Library\\MyLibrary1

If you have a structure like this you have to refer to \\Library\\MyLibrary1\module instead of \\Library\\MyLibrary1

在您的settings.gradle中使用:

include ':MyLibrary1'
project(':MyLibrary1').projectDir = new File(settingsDir, '..\\Library\\MyLibrary1\module')

这篇关于将项目包含为具有相对路径的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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