Lahiru Chandima
Lahiru Chandima

Reputation: 24068

What happens if two android modules of the same android project use different support library versions?

I have an android project with two modules. I already have released this app to Google Play. Today I found that these two modules have used different support library version dependencies in their gradle files (in the version currently in production in Google Play).

Can having different support library versions in app modules cause unexpected problems?

Upvotes: 2

Views: 540

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317427

If there is a version conflict, gradle will automatically select the highest version available. Imagine an app project 'app' that includes a library module 'mylibrary'. I have set the compat lib version to 23.2.1 in 'app' and 23.2.0 in 'mylibrary'. The output of ./gradlew :app:dependencies shows which one gets selected in the end:

_debugCompile - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:23.2.1
|    +--- com.android.support:support-v4:23.2.1
|    |    \--- com.android.support:support-annotations:23.2.1
|    +--- com.android.support:animated-vector-drawable:23.2.1
|    |    \--- com.android.support:support-vector-drawable:23.2.1
|    |         \--- com.android.support:support-v4:23.2.1 (*)
|    \--- com.android.support:support-vector-drawable:23.2.1 (*)
+--- com.android.support:recyclerview-v7:23.2.1
|    +--- com.android.support:support-v4:23.2.1 (*)
|    \--- com.android.support:support-annotations:23.2.1
+--- com.android.support:design:23.2.1
|    +--- com.android.support:support-v4:23.2.1 (*)
|    +--- com.android.support:appcompat-v7:23.2.1 (*)
|    \--- com.android.support:recyclerview-v7:23.2.1 (*)
+--- com.android.support:percent:23.2.1
|    \--- com.android.support:support-v4:23.2.1 (*)
\--- project :mylibrary
     \--- com.android.support:appcompat-v7:23.2.0 -> 23.2.1 (*)

Notice the very last line where the compat lib for mylibrary gets upgraded to from 23.2.0 to 23.2.1. This will happen for any library with the same group and name components.

Yes, there can be problems when a version gets upgraded like this. If the changed version of the library is not backward compatible with the prior version, the code that references the older version might fail to compile with missing methods. For micro and minor version update, this is typically not a problem, but for major version updates it can be. It completely depends on the specific situation.

Upvotes: 6

Related Questions