Google Play Services Dependency Hell starring App Invites
It's not a movie title... it's an experience I had with Google App Invites recently.
This error made me lose roughly 3 days of work.All com.google.android.gms libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 8.3.0, 8.1.0. Examples include com.google.android.gms:play-services-base:8.3.0 and com.google.android.gms:play-services-measurement:8.1.0
Everything starts with me getting back to a project for which I worked 1-2 months before with the intent of updating the dependency used by that project on one of our company libraries.
So I go on and change:
This innocent line in depencencies turn red:
with the error I wrote above.
first tough: oh right! my cool library switched to play services 8.3.0
let's switch to 8.3.0 on this project too...
change it, gradle sync
SAME exact error....
ok, time to go deeper.
my app use these 2 play services dependencies: fitness and appinvite
the cool library use these two: analytics and location
no other dependencies in my project use any other play services libraries.
the error (I red it carefully at this point) said that the problem was with "measurement" part of play services, so which of my dependencies brough that in?
time to drop on the command line:
./gradlew app:dependencies --configuration compile
| +--- com.google.android.gms:play-services-base:8.1.0 -> 8.3.0
| | \--- com.google.android.gms:play-services-basement:8.3.0
| | \--- com.android.support:support-v4:22.2.0 -> 23.1.1
| | \--- com.android.support:support-annotations:23.1.1
| \--- com.google.android.gms:play-services-analytics:8.1.0 -> 8.3.0
| \--- com.google.android.gms:play-services-basement:8.3.0 (*)
what the.... !?
it is not brought in by anything. It's a DIRECT dependency which is NO WHERE to be found in my project
./gradlew app:dependencyInsight --configuration compile --dependency com.google.android.gms:play-services-measurement
[INSERT hours of painful try-something-crazy-gradle-sync-check-again-google-repeat cycle here, featuring: exclusion of transitive dependencies, generated and intermediate files analysis in the build directory, random version changes of any of the dependency my project had, buildToolsVersion, compileSDK, target SDK, reboot computer (yep I was desperate), swearing etc....]
then I remembered something (like 24 hours of wasted work time later) when I added app invites to that app I had to do something weird: add google-services.json file in the app/ folder of my project.
At the time I just dismissed the fact: "it works, whatever". I didn't had much time to investigate.
When integrating app invites I had to add this to the root directory build.gradle file (not the one of my app):
classpath 'com.android.tools.build:gradle:1.3.0' classpath 'com.google.gms:google-services:1.4.0-beta3'
it must be that google-services dependencies that takes care of using the json file and do stuff.
As it turned out it also silently injected a dependency to my project to the com.google.android.gms:play-services-measurement:8.1.0...
even knowing that I found no way of inspecting it, nor in the generated files nor in the gradle tools to inspect the project. I had to guess it! And figured out that if I was right changing the version of this google-services plugin it may had injected a more recent version of the play service library.
at the time the last version was: classpath 'com.google.gms:google-services:1.5.0-beta2
and changing it finally fixed my project!
I blame Google for those hours. And I think this is a major bug.
But there's no place to file it, or I couldn't find any (http://stackoverflow.com/questions/33342680/where-do-you-file-bugs-for-android-ios-google-products-or-services-appinvites
Honestly Google, WTF?!?
I'm writing this post in the hope that if any of you hit that same problem you'll be able to solve it quick, hopefully someone will find this by googling for the error message.