有一些gradle - android项目A.它取决于几个gradle子项目,每个项目位于自己的git存储库中,并通过git sub模块连接到我们的项目(我可以在我的owr存储库中查看它)作为我项目的子目录。)
项目hierarhy是:
└─ ProjectRootDir --- projectA
├─ gradle
├─ mainProject
│ └─ subprojectA --- submoduleA
│ ├─ libs
│ ├─ src
│ ├─ settings.gradle
│ └─ build.gradle
├─ relatedProjects --- folder for submodules
│ ├─ subprojectA --- submoduleA
│ │ ├─ library
│ │ ├─ gradle
│ │ ├─ libs
│ │ └─ relatedProjects --- related projects for submoduleA
│ │ ├─ subprojectAA --- first submodule of submoduleA
│ │ │ ├─ Test
│ │ │ ├─ libs
│ │ │ ├─ src
│ │ │ ├─ settings.gradle
│ │ │ └─ build.gradle
│ │ └─ subprojectAB --- first submodule of submoduleA
│ │ ├─ libs
│ │ ├─ src
│ │ ├─ tests
│ │ ├─ settings.gradle
│ │ └─ build.gradle
│ └─ subprojectB --- submodule of submoduleB
│ ├─ demo
│ ├─ gradle
│ ├─ library
│ ├─ settings.gradle
│ └─ build.gradle
├─ settings.gradle
└─ build.gradle
mainProject build.gradle
apply plugin: 'android'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile project(':relatedProjects:subprojectB:library')
compile project(':relatedProjects:subprojectA:library')
}
rootProject settings.gradle
include ':mainProject'
include ':relatedProjects:subprojectB:library'
include ':relatedProjects:subprojectA'
rootProject build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.+'
}
}
subprojectA settings.gradle
include ':library'
include ':relatedProjects:subprojectAA'
include ':relatedProjects:subprojectAB'
subprojectA build.gradle
apply plugin: 'android-library'
repositories {
mavenCentral()
flatDir {
name 'localRepository'
dirs 'src/main/libs'
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
sourceSets {
instrumentTest {
assets.srcDirs = ["src/tests/assets"]
res.srcDirs = ["src/tests/res"]
resources.srcDirs = ["src/tests/src"]
java.srcDirs = ["src/tests/src"]
}
}
}
dependencies {
compile project(':relatedProjects:submoduleAA')
compile project(':relatedProjects:submoduleAB')
}
但是当我尝试构建./gradlew assembleDebug时 我每次都收到错误
FAILURE: Build failed with an exception.
* Where:
Build file '.../ProjectRootDir/relatedProjects/submoduleA/library/build.gradle' line: 38
* What went wrong:
A problem occurred evaluating project ':relatedProjects:submoduleA:library'.
> Project with path ':relatedProjects:submoduleAA' could not be found in project ':relatedProjects:submoduleA:library'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
第38行是
compile project(':relatedProjects:submoduleAA')
但是当我运行./gradlew assembleDebug for submoduleA项目时一切正常。
每个人都请帮助我。我如何将一个项目与另一个项目中的子项目一起用作子项目(子模块)?
答案 0 :(得分:0)
Gradle构建只能有一个settings.gradle
,并且您只能在属于同一构建的项目之间具有项目依赖性。跨越构建边界,您通常通过(本地或远程)Maven或Ivy存储库交换二进制工件(外部依赖项)。当然,两个settings.gradle
可能包括一些相同的项目。 IntelliJ还具有将另一个Gradle构建添加到同一IntelliJ项目的功能,并且Android Studio中也可能存在此功能。