When you build up an Android library, but not sure if it works properly. When a company has multiple modules and want to allow their employees access and use module easily. Aritifactory is one tool that is useful for speeding up development cycles. You can publish your modules or libraries into Artifactory repositories, and only let people in localhost to use them.

How to install and setup Artifactory?

I am using Linux environment to build up Artifactory. Therefore, I will only talk how to install it in Linux system. If you don’t have Linux system, you can use virtual machine (Virtual Box) or host a Linux system in clouding system (AWS).

After you have Linux environment, please check if you have Java installed. If yes, check java -version to make sure it is at least SDK 8. If you don’t have java, downloaded and install it.

Then simply download Artifactory and unzip it.

Then you can run Artifactory by the following code:

1
$ARTIFACTORY_HOME/bin/artifactoryctl start

After that, you can check in your browser to see if Artifactory is setted up or not. The url is http://SERVER_DOMAIN:8081/artifactory. Now you are able to build up repositories and setup permissions if you are Admin.

If you want to build a repositories for Android APKs/AARs file, you can click on the user’s button and choose quick setup, then you can setup a Gradle repository for Android Libraries.

How to upload APKs/AARs into Artifactory

In your Library Gradle file, add the following lines:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

def packageName = 'com.package.company'
def libraryVersion = '1.0.0'

publishing {
publications {
aar(MavenPublication) {
groupId packageName
version libraryVersion
artifactId project.getName()
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar";
}
}
}

artifactory {
contextUrl = "http://SERVER_DOMAIN:8081/artifactory"
publish {
repository {
repoKey = 'gradle-release-local'
username = 'YourUserName'
password = 'YourPassWord'
}
defaults {
publications('aar')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}

Now when you check Gradle artifactoryPublish you can publish your AARs to your Artifactory repository. However, the dependencies in your gradle file is not included. It means when your client uses your modules, they still need to add other libraries you included in your library. Therefore, you can add dependencies in your pom file.

your pom file can be defaultly generated by generatePomFileForAarPublication by gradle. Then you can edit it in your build->publications->aar folder. Here is a sample to add a dependency. For example, translate gradle dependency:

1
compile 'com.android.support:support-v4:25.4.0'

In pom file, it should be:

1
2
3
4
5
6
7
8
<dependencies>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-v4</artifactId>
<version>25.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

If you are not allowed to upload your edited pom file, you can go to your artifactory repository and check setting Suppress POM Consistency Checks to be true.

Now you are able to upload your AAR files and your dependencies in pom files into your localhost Artifactory.

###How to use Libraries in Artifactory?

In your App, if you want to use modules already uploaded in Artifactory, you need to connect to your repository url and tell your credentials. Add those lines in to your project gradle file:

1
2
3
4
5
6
7
8
9
10
11
12
13
allprojects {
repositories {
google()
jcenter()
maven {
url "http://SERVER_DOMAIN:8081/artifactory/gradle-release-local"
credentials {
username = 'YourUserName'
password = 'YourPassWord'
}
}
}
}

Then you can simple import libraries in your app gradle files by adding up dependencies like:

1
implementation 'com.package.company:libraryname:1.0.0'

That is it. You now can use Methods and Classes open in your Libraries. If it is not successful, clean cache, and rebuild your project.