Search code examples
androidgradleversions

Android: best way to handle versions of Google dependencies in a library project


I maintain an Android open source library, via GitHub and jCenter. That library uses parts of Google play services and Android's support libraries.

Android Studio gives a warning when you don't reference a specific version of those libs in build.gradle. However, when we do, we constantly have to "chase" Google's releases, or our uses have version mismatch.

What is a good way to handle this?


Solution

  • I run into this issue all the time with large projects that use many 3rd party dependencies. What I tend to do is exclude some of the transitive dependencies from the 3rd party libs and make sure to include my own. This does require that you review the androidDependencies in your app and make sure that you are finding where the transitive dependencies are coming from.

    Here is a link to the gradle: https://docs.gradle.org/current/userguide/dependency_management.html#sub:exclude_transitive_dependencies

    Here is a simple example of what I have done in one of my projects:

     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })