Android library maven dependency from gitlab local server's private repository - android

We have a Gitlab local server with private repositories. It's only accesible inside our network.
We want a way to distribute our Android libraries as maven dependencies, instead of copying modules, aar/jar etc...
An example of what we want to achieve. We have an Android project A, and an Android library B, both in our Gitlab local server, A has B as dependency. This would be our A's app build gradle file:
dependencies {
...
implementation '...B'
}
From our understanding jitpack only supports public Gitlab servers for self hosted gits.
https://jitpack.io/docs/PRIVATE/#self-hosted-git

I ended up using JFrog's Artifactory OSS (open source). A repository where you will store your libraries. In my case through gradle, there are more solutions like maven, nugget etc, gradle is free, the others require to pay.
What you'll have to make this works:
A server for the Artifacotry OSS.
A .gitlab-ci.yml file in your Android's project root directory.
A publishing gradle task in your Android's library gradle file.
Access to your GitLab's library repository to define variables.
In the .gitlab-ci.yml is specified which GitLab's branch to listen to, so every time you make a push in that branch a pipeline will execute with the docker settings specified in .gitlab-ci.yml. This will download everything necessary in the docker to execute the gradle publishing task in your Android's library gradle file.
Artifactory OSS documentation
GitLab CI documentation

Related

How to publish android library to subversion and use it on projects

There are many posts about publishing android library in github. Is there any way to publish android library to the svn?
EDIT:
I have created a libray and build the aar file. I have imported the aar file in to a tag of the svn. (Ex: svnpath/project/tags/library0.0.1.aar)
I want to use this library in a separate project. I want to use this library as
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
like this. how can i achieve this?
As discussed in the comments, Subversion (SVN) is not an appropriate tool for what you are trying to achieve. Subversion is a version control system which manages the versioning of source code files and associated resources, much in the same manner as Git does.
What you are looking for is a dependency management system using Maven, for example Artifactory. This will allow you to publish your .aar files to either a public-facing or private repository and import those dependencies into your build.gradle file. Unfortunately the process for setting up such a service is too broad for the scope of this question, but once you have it up and running you can add it to your build.gradle file under the repositories section:
repositories {
maven {
url "<url of Maven server>"
credentials {
// If you choose to use authentication
username = <your artifactory username>
password = <your artifactory password>
}
}
}

How to use a Gradle dependency with local modifications?

I have an Android application using an Android library. The library is a pretty big open-source project on GitHub, and its authors publish the artifacts to Bintray. I can specify the dependency with the usual syntax dependencies { implementation 'group:artifact:version' } in the app's 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. But how can I tell my app to use the library I built locally, instead of the one in 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.
I think the solution involves publishing to a local Maven repository. 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.
Bintray-based projects have the install task. That's the one to be used instead of publishToMavenLocal.
When using install, the artifact version is automatically set to X.X.X before publishing to the local repository. Therefore, in order for the app to pick up the local library, you have to edit the implementation row to group:artifact:X.X.X.
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.

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. I understand that we dont have any closures/methods in gradle to directly get files from a http url.
Therefore am using ant's getmethod to download the library from gitlab.
Here is the code am using in my gradle file to get the library.
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. 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.
However, if I manually download the same aar file and reference it in the libs folder it works absolutely fine.
Any idea why does this happen?
Is there any other way to download a aar file from a gitlab server apart from ant.get?
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
The same problem occurs for jar files as well.
I dont think I have a direct solution for the problem as gradle does not have an api for this. 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.
The artifactory OSS version can be downloaded from here
I chose artifactory because it was much simpler and had a great 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.
After setting up, your libraries can be accessed as below.
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.
I hope this helps.
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
}

Android studio - Gradle - GitHub Repo

Does anyone have an idea if it's possible to use a github repo as a dependency, without it being published to maven central.
Let's say I'm developing an android library that has it's own github repo. I'd like to be able to "compile" this library has gradle dependency, in my android studio project, without having to publish to maven central (at least for the moment).
In other words : I want to use a dependency that is not on maven central. It's a straight github repo (an android library that also uses gradle).
I'd like my build.gradle to do something like this :
dependencies {
// Google Play Services (normal dependency)
compile "com.google.android.gms:play-services:5.2.08"
// The library I want to pull from github
compile "path_to_my_github_repo"
}
Thanks!
You can do that with Jitpack with Maven, Gradle and sbt.
However, I would strongly suggest to use binary artifact instead so that you are guaranteed that it is the same upon each build of your application, you control the artifact storage and you are using the official release of a project and not some downstream build. It will also make your builds much faster and more stable.
Publishing to the Central Repository is free, easy and well documented at e.g. http://central.sonatype.org/pages/producers.html and specifically for Gradle at http://central.sonatype.org/pages/gradle.html. You can also find lots of real world examples on the Nexus community site.
If you do not control the project you want to consume, I would suggest to send these pointers to the project and maybe even help them with a pull request ;-)
This should be possible and there is an unofficial gradle plugin called Gradle Git Repo plugin that claims to do what you're looking for. Note however, that I did not play with it myself to verify that it works.
What you need to use is a binary repository. It will contain your dependencies during development.
If you plan to publish your package to jcenter (and maven central) eventually, you can get a free Artifactory account in oss.jfrog.org.
Once doing that, your CI server can deploy your dependency to it and Gradle will resolve it from there.

How to reference to library if it's not in project structure in Gradle?

Maven stores artifacts in local repository so i can build library and project separately and library reference (dependency) in project can be resolved if library is already installed in local repository. How to do it using Gradle? (relates to android and java projects)
CI builds should always share binaries via a binary repository (e.g. Artifactory or Nexus), not via a local repository. If you want to share the library as source, You can have two multi-project builds that both include the library as a subproject. Subprojects can be located anywhere on the file system; for details, see the "multi-project builds" chapter in the Gradle User Guide.

Categories

Resources