androidgradlemulti-project

Gradle: how to include an existing, complete project as a subproject?


I git clone a complete gradle project "CompleteGradleProjA" from github and include it into my local project as a submodule. By "complete gradle project" I mean that I can go into directory "CompleteGradleProjA" and issue command

cd CompleteGradleProjA && gradle build

to build it.

My directory structure looks like this,

MyProj
  |---CompleteGradleProjA
  |   |---build.gradle
  |
  |---build.gradle

My question is: How can I call "CompleteGradleProjA/build.gradle" without changing anything of it from my root "build.gradle"?

The following root "build.gradle" config does not help.

apply plugin: 'java'
dependencies {
  compile project(':CompleteGradleProjA')
}

I got error message

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':compileJava'.
> Could not determine the dependencies of task ':compileJava'.

"CompleteGradleProjA" is an android porject and "CompleteGradleProjA/build.gradle" looks like this

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

Solution

  • CompleteGradleProjA/build.gradle

    apply plugin: 'com.android.library'
    // if your project isn't library then use this:
    // apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 22
        buildToolsVersion '21.1.2'
    
        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 22
        }
    }
    
    dependencies {
        compile 'com.android.support:support-v4:22.2.0' // if needed
    }
    

    settings.gradle

    include ':CompleteGradleProjA'
    

    Use apply plugin: 'com.android.library' or apply plugin: 'com.android.application' instead of apply plugin: 'java'