4

Two of the components of an android application depends on two different versions of the same Library. (google protobuf).

ie. Module 1 depends on protobuf2, while Module 2 needs protobuf3.

The required parts of the the two versions are mutually exclusive and hence not interchangeable.

So far gradle internally use the lastest version from the two versions and one module breaks at a missing method.

Is it possible to force gradle to use version 2 for the 2's dependent and version 3 for the 3's dependent? Or else what are the possible alternatives to address this sort of an issue?

Cheers.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
Nowa Concordia
  • 709
  • 6
  • 23

1 Answers1

1

I guess, if you are having different build.gradle files for your respective modules and these modules are linked by some parent build.gradle file, then there should not be any issue.

I'm not an expert on gradle but using maven for a long time and these are somehow similar in nature.

In maven, I can declare the same dependency with different versions in different module's pom file :

<dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>3.2.2</version>
</dependency> 

In another, pom file you can declare different versions :

<dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>2.13.2</version>
</dependency>

Now, you can see two different versioned jars will get added under 'Maven-dependencies' of different modules.

In same pom file it won't be possible without using profiling. Otherwise it will always pick the jar which is nearest to it's dependency tree out of 2-3 different version jars.

Punit
  • 324
  • 1
  • 4
  • 17
  • This make sense. In our case the latest version of the dependency is added as a dependency to the primary build.gradle, so i guess we can try compiling that specific code to another sub-module with seperate build.gradle file and see. Thanks for the answer will update with the results. – Nowa Concordia Sep 18 '17 at 09:18