Reputation: 1363
In my Android application I have google play billing implementation, I have it defined in build.gradle as:
implementation 'com.android.billingclient:billing:1.2'
Also, I have my self created library for some shared code to integrated into my project. In that library I want to implement google play billing implementation code. For that as well I have define the billing library in build.gradle file of library.
I am using gradle version :
'com.android.tools.build:gradle:3.2.0'
Is there any option to define the library only one place (build.gradle) and use it from both the places?
Upvotes: 1
Views: 1196
Reputation: 1498
As of Gradle Plugin version 3.0.0, there is a nicer way to do this. We can control whether each dependency is available for only the current module, or for the current module AND any modules which depend on it. This will allow us to easily share dependencies across modules within a project.
Here's how we used to declare dependencies:
compile 'com.android.billingclient:billing:1.2'
Here are the new configurations which should replace compile:
implementation 'com.android.billingclient:billing:1.2'
this dependency is only used within this modAPI
api 'com.android.billingclient:billing:1.2'
this dependency will also be available in any builds that depend on this module. Assuming that we have a module named 'library' that is consumed by the 'app' module, we can use the api configuration to declare that the dependency should be shared with any module that depends on it.
library module build.gradle
dependencies {
// dependencies marked 'implementation' will only be available to the current module implementation 'com.squareup.okhttp:okhttp:2.4.0'
// any dependencies marked 'api' will also be available to app module
api 'com.android.billingclient:billing:1.2'
}
app module build.gradle:
dependencies {
// declare dependency on library module
implementation project(':library')
// only need to declare dependencies unique to app
implementation 'example.dependency:1.0.0'
}
Please see this for further information and diagrams. https://medium.com/@julesrosser/handling-gradle-dependencies-in-multiple-module-android-projects-9e590c3d20dc
Upvotes: 4