How does gradle handle multiple modules with different versions of the v4 support library?

I have an Android project that depends on different modules, and each module depends on a different version of the android support-v4 support library.

1) My application also depends on the latest android support-support library v4 (revision 21), so in this build.gralde I put this line:

dependencies { compile 'com.android.support:support-v4:21.0.0' } 

2) The Facebook SDK module (v.3.15), which also depends on the v4 support library for Android, but in version 13 and the build.gradle file it says:

 dependencies { compile 'com.android.support:support-v4:13.0.+' compile files('../libs/bolts.jar') } 

3) and another module, which in this case can be called Module3, also depends on support-v4, but with a different version than other modules, for example:

 dependencies { compile 'com.android.support:support-v4:19.0.+' compile files('../libs/bolts.jar') } 

Questions:

1) How does gradle handle different versions of the v4 support library?

2) What is he doing exactly?

3) What does this mean in terms of apk size?

+6
source share
1 answer

In this case, Gradle will fail (tested on my skin, and I did not find other solutions). Unfortunately, you must use the same version of support on any module.

From docs.gradle.com :

Gradle offers the following conflict resolution strategies:

  • The newest . The latest version of the dependency is used. This is the default Gradle strategy, and it is often the appropriate choice if the versions are backward compatible.

  • Failure . A version conflict leads to a build failure. This strategy requires that all version conflicts be resolved explicitly in the build script. For details on how to explicitly select a specific version, see ResolutionStrategy.

Although the above strategies are usually sufficient to resolve most conflicts, Gradle provides smaller mechanisms for resolving version conflicts:

  • Setting the dependency of the first level as mandatory . This approach is useful if the dependency in the conflict is already a first-level dependency. See Examples in DependencyHandler .

  • Setting any dependency (transitional or not) as mandatory . This approach is useful if the conflict dependency is a transitive dependency. It can also be used to force version of dependencies of the first level. See Examples in ResolutionStrategy

  • Dependency Resolution Rules is an incubation feature introduced in Gradle 1.4 that gives you small-scale control over the version selected for a specific dependency.

+1
source

Source: https://habr.com/ru/post/978743/


All Articles