Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

same library in different packages doesn't work

After updating to the latest gradle, I get a weird error when building the project:

[:feature_x, :feature_y] all package the same library  [com.github.PhilJay:MPAndroidChart].

I have indeed added this library in both features. They are set as a dependency like:

api "com.github.PhilJay:MPAndroidChart:$rootProject.MPAndroidChart"

What is wrong with this?

like image 934
Gillis Haasnoot Avatar asked Sep 27 '18 20:09

Gillis Haasnoot


1 Answers

As of 2018-10, this is expected behavior, according to this issue in Google's issue tracker:

Yes, multiple non-base features depending on the same library is currently not supported because both of the features will package the library, but there's no guarantee that they'll package the same version of the library, which can lead to crashes at runtime. We opted to fail the build in these cases to prevent unexpected behavior at runtime.

Unfortunately, adding the library as a dependency to the base module is the suggested workaround for this.

like image 163
marianosimone Avatar answered Oct 04 '22 04:10

marianosimone