How gradle merge different aar versions of different lib in Android?

I have two library, which depends on the same aar, in first library, I use this:

compile ''

but second library, I use:

compile ''

the 0.0.1 and 0.0.2 have totally different api, if I change the version in the first library to 0.0.2, it will get compilation error. The dependency tree is like this:

|-library 1
|-library 2

When I write this, the compilation can pass, and run OK. I just wonder why this works, how the gradle merge the arrs.