Reputation: 17264
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 ?
Upvotes: 5
Views: 3991
Reputation: 12992
From the docs:
In Android projects, this is a bit more complicated because there could be a large number of the same task and their name is generated based on the Build Types and Product Flavors.
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.
Upvotes: 13