Skip to content

Instantly share code, notes, and snippets.

@dbachelder
Forked from goldierox/build.gradle
Last active August 29, 2015 13:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbachelder/9534270 to your computer and use it in GitHub Desktop.
Save dbachelder/9534270 to your computer and use it in GitHub Desktop.
import com.android.build.gradle.AppPlugin
import com.android.build.gradle.LibraryPlugin
subprojects {
// This is an annoying hack to get around the fact that the Gradle plugin does not support
// having libraries with different minSdkVersions. Play Services has a min version of 9 (Gingerbread)
// but Android Maps Utils supports 8 (Froyo) still
it.afterEvaluate { subProject ->
// is this a library or an app?
if(subProject.plugins.hasPlugin(AppPlugin.class) || subProject.plugins.hasPlugin(LibraryPlugin.class)) {
// variants are accessed in different ways for each..
def variants = subProject.plugins.hasPlugin(AppPlugin.class) ? android.applicationVariants : android.libraryVariants
variants.all{ variant ->
variant.processManifest.doFirst {
File manifestFile = file("${buildDir}/exploded-bundles/ComGoogleMapsAndroidAndroidMapsUtils03.aar/AndroidManifest.xml")
if (manifestFile.exists()) {
println("Replacing minSdkVersion in Android Maps Utils in sub-project $subProject")
String content = manifestFile.getText('UTF-8')
content = content.replaceAll(/minSdkVersion="8"/, 'minSdkVersion=\"9\"')
manifestFile.write(content, 'UTF-8')
println(content)
}
}
}
}
}
}
@dbachelder
Copy link
Author

This version is for a gradle project with multiple android apps and/or library projects.

@dbachelder
Copy link
Author

Put it in the top level build.gradle

@ignaciogs
Copy link

I get an error message: "Could not find property 'AppPlugin' on project ':XXXXX'. "

I fix it replacing AppPlugin.class by "android" and LibraryPlugin.class by "android-library"

..
..
if(subProject.plugins.hasPlugin("android") || subProject.plugins.hasPlugin("android-library")) {
// variants are accessed in different ways for each..
def variants = subProject.plugins.hasPlugin("android") ? android.applicationVariants : android.libraryVariants
..
..

@dbachelder
Copy link
Author

@ignaclogs sorry, i didn't see this earlier!

you just need some imports:

import com.android.build.gradle.AppPlugin
import com.android.build.gradle.LibraryPlugin

@dbachelder
Copy link
Author

But your way seems fine too... probably less brittle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment