简体   繁体   English

如何在 AAR 中提供 compileOnly 依赖项?

[英]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.我正在尝试创建一个 Android 库myLibrary ,它将作为 AAR 交付给我公司的其他人。

Many of the dependencies of myLibrary are APIs for communicating with the phone's hardware (barcode scanning, etc.). myLibrary 的许多依赖是用于与手机硬件(条形码扫描等)通信的 API。 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;这些第三方库之一需要使用compileOnly而不是implementation将其添加到您的项目中,因为提供的 JAR 文件包含存根实现; the full implementation is provided by the device.完整的实现由设备提供。

In my library module's build.gradle:在我的库模块的 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.在这个例子中,Vendor3 的设备硬件 API 是 compileOnly。

My use case is that I want consumers of myLibrary to be able to extend the functionality I provide.我的用例是我希望 myLibrary 的使用者能够扩展我提供的功能。 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.意思是,如果我有一个 MyCoolVendor3Class 并且他们想要扩展它并自定义它的某些方面,他们将无法触及 Vendor3 API。

How can I provide myLibrary's dependent compileOnly API to consumers of the library without using implementation ?如何在不使用实现的情况下向库的使用者提供 myLibrary 的依赖 compileOnly API? Or will they need to get their hands on the Vendor3 Jar on their end to make this approach feasible?或者他们是否需要亲自接触 Vendor3 Jar 才能使这种方法可行?

Thanks.谢谢。

Note: You can't use the compileOnly configuration with AAR dependencies.注意:您不能将 compileOnly 配置与 AAR 依赖项一起使用。 Ref from: https://developer.android.com/studio/build/dependencies参考: 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我觉得可能是jar里打包的资源导致的,只编译classes文件就可以了,但是资源呢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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