Android gradle:多项目构建,顶级build.gradle

pka*_*pka 5 android gradle android-gradle-plugin

我有一个多项目Android构建系统.该项目的结构如下:

Root Dir
   |
    settings.gradle
   |
    build.gradle
   | 
    Apps
      |
       app 1
         |
         build.gradle
      |
       app 2
         |
         build.gradle
    |
    Libs
      |
       lib 1
         |
         build.gradle
      |
       lib 2
         |
         build.gradle
Run Code Online (Sandbox Code Playgroud)

所有的应用程序和库都有常见的android配置.

在根级build.gradle我有以下内容:

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

      defaultConfig {
         minSdkVersion 14
         targetSdkVersion 19
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

接下来我想到将以下内容添加到app 1中的build.gradle中

apply plugin: 'com.android.application'

android {
   sourceSets {
      main {
         manifest.srcFile 'AndroidManifest.xml'
         java.srcDirs = ['src']
         res.srcDirs = ['res']
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Cannot add extension with name 'android', as there is an extension already registered with that name.
Run Code Online (Sandbox Code Playgroud)

在Android的gradle插件中,是否有一种方法可以通过子模块扩展"主机配置"?

Jim*_*Jim 2

我遇到了类似的问题 - 这与您如何包含插件有关。

在你的“根”构建文件中,你有:

apply plugin: 'android'
Run Code Online (Sandbox Code Playgroud)

在您的应用程序中您有:

apply plugin: 'com.android.application'
Run Code Online (Sandbox Code Playgroud)

更改根目录以匹配应用程序插件。