Android:如何在Settings.gradle中包含项目

时间:2015-07-28 18:28:57

标签: android gradle android-gradle

遵循我的项目目录结构:

dev/
   android/
           apps/ 
                project2
   project1

我想在项目2中包含项目1.所以我试图在settings.gradle文件中添加这个项目。以下是我的settings.gradle文件的内容:

include ‘:project2', ‘dev:project1'
project('../../..project1').projectDir = new File(settingsDir, ‘:project1’)

build.gradle文件:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project('../client/project1')
}

当我尝试构建我的项目时,它给了我这个错误:

Error:Project with path '../../.. project1' could not be found.

2 个答案:

答案 0 :(得分:2)

我通过在settings.gradle

中使用以下代码解决了这个问题
include ‘:project2', ‘dev:project1'
project(':project1').projectDir = new File(settingsDir, ‘../../../project1’)

的build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':project1')
}

答案 1 :(得分:0)

假设您将settings.gradle文件放在根文件夹中:

include ':dev:project1', ':dev:android:apps:project2'