Include projects as modules with relative path

2019-02-26 19:04发布

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

What I've tried is the following:

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

But I get this error: Error:Configuration with name 'default' not found.

Gradle

2条回答
一夜七次
2楼-- · 2019-02-26 19:37

Error:Configuration with name 'default' not found

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

Make sure that you are referring to the module inside the Library not the root folder.

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

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

In your settings.gradle use:

include ':MyLibrary1'
project(':MyLibrary1').projectDir = new File(settingsDir, '..\\Library\\MyLibrary1\module')
查看更多
叼着烟拽天下
3楼-- · 2019-02-26 19:40

To do this you must follow this step:

  1. Open your project in Android Studio
  2. Go to File > Import Module and import the library as a module
  3. Go to File > Project Structure > Modules
  4. Locate your main project module, click on it. It should have a few android libraries, such as: support-v4, etc.
  5. Click on the more on the left green "+" button > Module dependency
  6. Select "your Library"

or follow Androd's documentation

查看更多
登录 后发表回答