Skip to content

Instantly share code, notes, and snippets.

@jkasten2
Last active September 20, 2017 11:36
Show Gist options
  • Save jkasten2/d535a35fbd9d0483ccc3e6e7861d2dca to your computer and use it in GitHub Desktop.
Save jkasten2/d535a35fbd9d0483ccc3e6e7861d2dca to your computer and use it in GitHub Desktop.
/**** #### Problem This Solves #### ****/
// Sometimes libraries added with "compile" will include their own dependencies.
// This can conflict with specific versions in your project or cause automatic upgrades
// overriding your specified versions as gradle resolves the highest value.
// A simpile workaround is to use the `force` flag on compile to override specific modules
// however this can be a pain to hunt down and define if there are multipile modules and groups.
/**** 1. How to use *****/
// 1.1 Place this your app's buidle.gradle and it will force override
// all Google Play services (GMS) and Android Support Libraries versions.
// 1.2 Make sure to update the versions below.
def versionGroupOverrides = [
// Google Play Services library
'com.google.android.gms': '10.2.+',
// Android Support Library
'com.android.support': '24.0.0'
]
configurations.all { resolutionStrategy {
failOnVersionConflict()
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def versionOverride = versionGroupOverrides[details.requested.group]
if (versionOverride)
details.useVersion(versionOverride)
}
}}
/**** 2. Check resulting overrides ****/
// 2.1 Run the following from the terimal / command line
// macOS / Linux:
// ./gradlew app:dependencies
// Windows:
// gradlew.bat app:dependencies
// 2.2 Check to ensure that any com.android.support under any com.google.android.gms isn't being overriden.
// This can create runtime issues so change the com.android.support version to match.
// Example below of com.android.support:support-v4:24.0.0 being overriden by 23.0.0
// under com.google.android.gms:play-services-basement:10.2.1
/*
// EXAMPLE: Google Play Services dependency chain
+--- com.google.android.gms:play-services-games:8.3.0 -> 10.2.1
| +--- com.google.android.gms:play-services-base:10.2.1
| | +--- com.google.android.gms:play-services-basement:10.2.1
| | | \--- com.android.support:support-v4:24.0.0 -> 23.0.0 *** NOTE: Need to change your override to 24.0.0)
| | | \--- com.android.support:support-annotations:23.0.0
*/
// 3. Check versions of other libraries if they defined ranges.
// 3.1 Some libaries just use :+ to use the latest version but other include a range.
// 3.2 Make sure your not overriding outside this range if possible.
// 3.3 Try to update the parent library if need to use even a newer version of GMS or the support library.
/*
EXAMPLE: Our override of 10.2.1 fits within the 8.3.0 [inclusive] to 10.3.0 (exclusive) below so we are good!
\--- com.onesignal:OneSignal:3.+
+--- com.google.android.gms:play-services-gcm:[8.3.0,10.3.0) -> 10.2.1 (*)
+--- com.google.android.gms:play-services-location:[8.3.0,10.3.0) -> 10.2.1 (*)
+--- com.android.support:customtabs:[23.0.0,25.4.0) -> 23.0.0 (*)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment