[英]How to use a Gradle dependency with local modifications?
I have an Android application using an Android library. 我有一个使用Android库的Android应用程序。 The library is a pretty big open-source project on GitHub, and its authors publish the artifacts to Bintray. 该库是GitHub上一个相当大的开源项目,其作者将工件发布到Bintray。 I can specify the dependency with the usual syntax dependencies { implementation 'group:artifact:version' }
in the app's build.gradle
. 我可以在应用程序的build.gradle
使用常规语法dependencies { implementation 'group:artifact:version' }
指定依赖build.gradle
。
Now I want to change some code in the library. 现在,我想更改库中的一些代码。 I git clone
it on my machine, I make my changes, then I build the library. 我git clone
它git clone
到我的机器上,进行更改,然后构建库。 But how can I tell my app to use the library I built locally, instead of the one in Bintray? 但是,如何告诉我的应用使用本地构建的库,而不是Bintray中的库?
I don't want to follow the approach in Gradle Local Project Dependency , because that means that the library code is now part of the application project, but I really want to keep things separated. 我不想遵循Gradle Local Project Dependency中的方法 ,因为这意味着库代码现在已成为应用程序项目的一部分,但是我真的想保持分离。
I think the solution involves publishing to a local Maven repository. 我认为该解决方案涉及发布到本地Maven存储库。 I followed the guide at https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 but the app's Gradle is still picking the original library from Bintray. 我遵循了https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02上的指南,但该应用程序的Gradle仍在从Bintray选择原始库。
Bintray-based projects have the install
task. 基于Bintray的项目具有install
任务。 That's the one to be used instead of publishToMavenLocal
. 那就是要使用的publishToMavenLocal
而不是publishToMavenLocal
。
When using install
, the artifact version is automatically set to XXX
before publishing to the local repository. 使用install
,在发布到本地存储库之前,工件版本会自动设置为XXX
。 Therefore, in order for the app to pick up the local library, you have to edit the implementation
row to group:artifact:XXX
. 因此,为了使应用能够提取本地库,您必须将implementation
行编辑为group:artifact:XXX
。
As the guide https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 suggests, you also need to add mavenLocal()
as the first entry in the repositories
section in the top-level build.gradle
of the application. 正如指南https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02所建议的那样,您还需要添加mavenLocal()
作为repositories
部分中的第一个条目。应用程序的顶级build.gradle
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.