简体   繁体   中英

How to provide a compileOnly dependency in an AAR?

I'm attempting to create an Android library myLibrary which will be delivered as an AAR to others in my company.

Many of the dependencies of myLibrary are APIs for communicating with the phone's hardware (barcode scanning, etc.). It's a requirement of one of these third party libraries to add it to your project with compileOnly instead of implementation , as the provided JAR file contains the stub implementation; the full implementation is provided by the device.

In my library module's build.gradle:

implementation files('libs/Vendor1.jar')
implementation files('libs/Vendor2.jar')
compileOnly files('libs/Vendor3.jar')

In this example, Vendor3's API to the device hardware is compileOnly.

My use case is that I want consumers of myLibrary to be able to extend the functionality I provide. Meaning, if I have a MyCoolVendor3Class and they want to extend it and customize some aspect of it, they won't be able to touch the Vendor3 API.

How can I provide myLibrary's dependent compileOnly API to consumers of the library without using implementation ? Or will they need to get their hands on the Vendor3 Jar on their end to make this approach feasible?

Thanks.

Note: You can't use the compileOnly configuration with AAR dependencies. Ref from: https://developer.android.com/studio/build/dependencies

I think it may be caused by the resources packed in the jar, it's ok to compileOnly the classes files, but what about the resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM