Reputation: 4101
Scenario
I have two Android libraries:
Library B depends on Library A and includes it from its build.gradle.
My Android app needs to use Library B and some base classes from Library A. The only success I've had in doing this is including both libraries in my Android app's build.gradle and setting transitive to false.
Question:
Is there a way for me to only add Library B and have access to its dependency from my Android app?
Android Studio
Android Studio 3.1 Canary
Build #AI-171.4415322, built on October 24, 2017
JRE: 1.8.0_152-release-1012-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6
Gradle
3.1.0-alpha01
Upvotes: 4
Views: 3352
Reputation:
From comments if you need to use library A inside your app and your library A included into B using implementation project(':LibA')
, then it won't be a transitive to your main app.
You have to include it into B using api
, api project(':LibA')
.
The api
configuration should be used for dependencies that are exported to external modules (transitive dependency). Vice-Versa implementation
configuration should be used for dependencies that are internal to the component (not transitive dependency).
Upvotes: 4
Reputation: 22637
That's called a transitive dependency.
Gradle, and all other dependency systems handle this automatically. If B needs A, you get A. If you are not getting A, that means B's dependencies are not correct.
Whether you should explicitly call out A in your dependencies is a debated topic. I'm of the camp that you should not. My reasoning is that you can end up with something like this,
include B(v1.0) -depends on-> A(1.0)
include A(1.1)
Now, which version of A gets compiled into your app and used at runtime? A 1.0 or A 1.1? The answer depends on the implementation of the build system.
Upvotes: 2