将项目包含为具有相对路径的模块

将项目包含为具有相对路径的模块

问题描述:

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

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