Android gradle: creating multiple projects, creating top level build.gradle

I have a multi-project Android system for Android. 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 applications and libraries share a common Android configuration.

At the Root build.gradle level, 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 about adding the following to build.gradle in application 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 โ€œmain android configurationโ€ that can be extended with a submodule?

+5
source share
1 answer

I had a similar problem - and this has to do with the way you enable your plugins.

In your "root" build file, you have:

 apply plugin: 'android' 

In your application you have:

 apply plugin: 'com.android.application' 

Change the root to match the application plugin.

+2
source

Source: https://habr.com/ru/post/1205143/


All Articles