Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gradle: Multi project build, top level build.gradle

I have a multi-project Android build system. The structure of the project is as follows:

Root Dir
   |
    settings.gradle
   |
    build.gradle
   | 
    Apps
      |
       app 1
         |
         build.gradle
      |
       app 2
         |
         build.gradle
    |
    Libs
      |
       lib 1
         |
         build.gradle
      |
       lib 2
         |
         build.gradle

All the apps and libraries have common android configration.

At the Root level build.gradle I have the following:

subprojects {
   apply plugin: 'android'
   android {
      compileSdkVersion "Google Inc.:Google APIs:19"
      buildToolsVersion "20.0.0"

      defaultConfig {
         minSdkVersion 14
         targetSdkVersion 19
      }
   }
}

Next I thought of adding the following to the build.gradle in app 1

apply plugin: 'com.android.application'

android {
   sourceSets {
      main {
         manifest.srcFile 'AndroidManifest.xml'
         java.srcDirs = ['src']
         res.srcDirs = ['res']
      }
   }
}

I get the following error:

Cannot add extension with name 'android', as there is an extension already registered with that name.

In the gradle plugin for android, is there a way to have a "master android configuration" which can be extended by a sub-module?

like image 425
pka Avatar asked Oct 31 '22 15:10

pka


1 Answers

I had a similar problem - and it has to do with how you are including your plugins.

In your "root" build file you have:

apply plugin: 'android'

In your app you have:

apply plugin: 'com.android.application'

Change the root to match the app plugin.

like image 126
Jim Avatar answered Nov 09 '22 04:11

Jim