简体   繁体   English

如何通过gradle从私有gitlab repo下载aar文件

[英]How to download a aar file from a private gitlab repo via gradle

I am trying to download a dependancy library mylibrary.aar from my gitlab repository via gradle . 我想下载一个扶养库mylibrary.aar从我gitlab通过库gradle I understand that we dont have any closures/methods in gradle to directly get files from a http url. 我知道我们在gradle中没有任何闭包/方法来直接从http url获取文件。

Therefore am using ant 's getmethod to download the library from gitlab . 因此我使用ant的getmethod从gitlab下载库。

Here is the code am using in my gradle file to get the library. 这是我在gradle文件中使用的代码来获取库。

task downloadlib {

ant.get(src: 'https://my-git-link/mylibrary.aar', dest: 'libs', verbose: 'on')

}

dependencies {

compile(name: 'mylibrary', ext: 'aar')

}

Problem : 问题:

The files which I download via the ant's get method seems to be corrupted/does not go through the download process properly. 我通过ant的get方法下载的文件似乎已损坏/未正确完成下载过程。 Not sure what goes wrong. 不确定出了什么问题。 The library does not get compiled and the dependencies cannot be resolved. 库未编译,无法解析依赖项。 When I try to extract the aar it again extracts to cgpz file in my mac.I havent tried in windows though. 当我尝试提取aar它再次提取到我的mac中的cgpz文件。虽然我还没在Windows中尝试过。

However, if I manually download the same aar file and reference it in the libs folder it works absolutely fine. 但是,如果我手动下载相同的aar文件并在libs文件夹中引用它,它可以正常工作。

  1. Any idea why does this happen? 知道为什么会这样吗?
  2. Is there any other way to download a aar file from a gitlab server apart from ant.get ? 除了ant.get之外,还有其他方法可以从gitlab服务器下载aar文件吗?

Any help on this is much appreciated. 对此有任何帮助非常感谢。

Note : I cannot use a locally built dependancy as all my libraries are on different repo and the project requirement mandates the same.Also, the code cannot be posted in github and thats the reason I did not choose jitpack 注意:我不能使用本地构建的依赖,因为我的所有库都在不同的repo上,并且项目要求要求相同。而且,代码无法在github中发布,这就是我没有选择jitpack的原因

The same problem occurs for jar files as well. jar文件也会出现同样的问题。

Do it like this example: 这样做是这样的:

implementation 'com.quickblox:quickblox-android-sdk-core:2.5.2@aar'
implementation('com.quickblox:quickblox-android-sdk-chat:2.5.2@aar') {
    transitive = true
    }

I dont think I have a direct solution for the problem as gradle does not have an api for this. 我不认为我有这个问题的直接解决方案,因为gradle没有这个api。 Instead what I did was, created my own maven repository using jfrog 's artifactory and hosted the libraries there so that all the developers can refer to the libraries from the internal artifactory. 相反,我所做的是,使用jfrogartifactory创建了我自己的maven存储库,并在那里托管了库,以便所有开发人员可以从内部工件中引用库。

The artifactory OSS version can be downloaded from here 可以从这里下载神器OSS版本

I chose artifactory because it was much simpler and had a great UI. 我选择了artifactory因为它更简单,并且具有很棒的UI。 Most of all it did not require setting up a separate github repository for this purpose as the code cannot be shared outside the organization. 最重要的是,它不需要为此目的设置单独的github存储库,因为代码无法在组织外部共享。

After setting up, your libraries can be accessed as below. 设置完成后,可以按如下方式访问您的库。

http://localhost:8081/artifactory . http:// localhost:8081 / artifactory

A brief description of setting up an artifactory is provided here 这里提供了设置工件的简要说明

After the libraries are hosted in your artifactory which can be located anywhere in your network, u or any other developer in your organization may access your libraries using the maven dependency manager in android. 将库托管在可以位于网络中任何位置的artifactory中之后,您或组织中的任何其他开发人员都可以使用android中的maven依赖管理器访问您的库。

I hope this helps. 我希望这有帮助。

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

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