If you have a lot of Android modules, you may want to avoid manually setting the same values in all of them. Because you probably have a mix of android and android-library project you can't apply these plugins through a subprojects closure. However you can set the value on the root project and then reference this from the modules. For example:
in the root project's build.gradle:
in all the android modules:
This way you only ever need to update one build.gradle.
Note that ext.* properties are dynamically created so you can add new properties of any type depending on your needs. You can then extend this to any other properties shared by some or all of your projects (minSdkVersion, targetSdkVersion, etc...)
The multi-apk support in the Google Play Store requires that all APKs of a same app have a different versionCode and that these values are ordered in a way that updates work.
You can easily dynamically create a composite versionCode that handles this.
For this, we use defaultConfig.versionCode as the actual version code that gets incremented on each release, and add to it a versionCode for each flavor dimension (group). Here's an example:
If you have a local jar or aar library that you want to use in more than one project, you cannot just reference it directly as a local dependency. This is because the android plugin will complain if it finds the same jar file twice when dexing the project and all its dependencies. (Note that right now you can't actually use a local aar file even if you only reference it once).
One way to fix this is to deploy the artifact in a repository. While it's possible, it might not be convenient due to the overhead of managing such a repository.
Another option is to create a new Gradle sub-project, and to make this project's published artifact be the jar or aar file that you want to reuse. Then you can simply have other Gradle sub-projects depend on this new sub-project.
In this new sub-project, simply create a build.gradle with the following: