0

There is some gradle - android project A. It's Depends on a few gradle sub-projects, that situated each on its own git repository, and connected, to our project by git sub module(I can look it in my owr repository as it sub directory of my project.)

project hierarhy is:

└─ 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')
}

But when i try to build ./gradlew assembleDebug i receive error every time

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.

line 38 is

       compile project(':relatedProjects:submoduleAA')

but when i run ./gradlew assembleDebug for submoduleA project everything is ok.

Every one please help me. How i can use one project with sub projects in another project as sub project(sub module)?

1

1 Answer 1

0

A Gradle build can only have a single settings.gradle, and you can only have project dependencies between projects belonging to the same build. Across build boundaries, you'd typically exchange binary artifacts (external dependencies), via a (local or remote) Maven or Ivy repository. Of course, two settings.gradle could include some of the same projects. IntelliJ also has a feature to add another Gradle build to the same IntelliJ project, and perhaps this feature also exists in Android Studio.

4
  • Thank you. I thought, that my problem that main project look for :relatedProjects:submoduleAA related to main project. Also I wanna know, how I can use subprojects (non artifacts) in my root project. because i think good way to use sub projects, and then compound it to main project. Jan 18, 2014 at 17:03
  • I don't understand the question. Perhaps ask a new question. Jan 18, 2014 at 17:04
  • I mean which way I can add subproject for subproject. Android Studio allows only create one level subprojects. When i try te create library subproject for exist one, Idea creates it in the root of project tree. why root project should know anything about subproject of subproject? Jan 18, 2014 at 17:16
  • It's the way Gradle works. settings.gradle declares all projects for the build, not just the immediate children. And subprojects { ... } (in case you were talking about that) refers to all projects below the current one in the logical project hierarchy (not just immediate children). You can learn more about these concepts in the "multi-project builds" chapter of the Gradle User Guide. Also check out the sample builds in the full Gradle distribution. Jan 18, 2014 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.