本文介绍了模块依赖 - Android Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目M1,M2下有2个模块

 项目
- M1
- M2

之前,我有M1作为我的主要应用程序。但是,需要新的应用程序M2,它与M1共享很多常见的东西。所以,我创建了一个具有M1依赖性的新模块M2。

为了达到这个目的,我修改了M1和M2的build.gradle,如下所示:


$ b M2:

  compile project(':M1 ')

M1:(更改为库)

  apply plugin:'com.android.library'

然而,这不起作用并抛出错误:

 找不到属性'applicationVariants 'on com.android.build.gradle.LibraryExtension_Decorated@6de81701。 

任何想法,关于如何解决这个问题?


$ b

为了为了解决这个问题,android对象有两个属性:
$ b $ applicationVariants(仅用于应用程序插件)

libraryVariants (仅适用于库插件)
$ b $ testVariants(对于两个插件)

这三个函数都返回ApplicationVariant的DomainObjectCollection ,LibraryVariant和TestVariant对象。





所以看起来你的build.gradle在M1中使用不适用于库项目的属性 applicationVariants 。因为我不知道你在做什么,我只能猜测你需要(1)用 libraryVariants 替换它,或者(2)将它移动到构建版本。 M2的gradle。

I've 2 modules under my project M1, M2

Project
  - M1
  - M2

Earlier, I had M1 as my primary application. However, there was a need for new application M2 that shared lot of common stuff with M1. So, I created a new module M2 with M1 as dependency.

To achieve this, I've modified build.gradle of M1 and M2 as follows:

M2:

compile project(':M1')

M1: (Changed to library)

apply plugin: 'com.android.library'

However, this doesn't work and throws up error:

Could not find property 'applicationVariants' on com.android.build.gradle.LibraryExtension_Decorated@6de81701.

Any idea, on how to solve this issue ?

解决方案

From the docs:

In order to fix this, the android object has two properties:

applicationVariants (only for the app plugin)

libraryVariants (only for the library plugin)

testVariants (for both plugins)

All three return a DomainObjectCollection of ApplicationVariant, LibraryVariant, and TestVariant objects respectively.

http://tools.android.com/tech-docs/new-build-system/user-guide

So it seems that your build.gradle in M1 uses the property applicationVariants which is not applicable to library projects. Since I don't know what you are doing exactly I can just guess that you either need to (1) replace that with libraryVariants or (2) move it to the build.gradle of M2.

这篇关于模块依赖 - Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:20