How to Host Maven Repository for Android AAR File on IIS
If you have a .jar or a .aar file for distribution, you can publish it to Maven central or jcenter. But the premise is your package has to be open source. If you want to distribute a commercial library, you’d better host a Maven repository yourself. Inspired by STEFFENWELLNER’s article, I have successfully set up a Maven repository on IIS. The post includes how to create an AAR project, how to configure IIS and URL, as well as how to create a testing project.
Uploading Android AAR to Local Maven Repository
Create an empty project without any activity.
Create an AAR module.
Create maven-publish.gradle:
apply plugin: 'maven'
group = "com.dynamsoft"
version = "1.0"
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'file:\\\\DESKTOP-3PCHU10\\site\\')
pom.project {
name 'dcs'
packaging 'aar'
description 'Document scanning API for Android'
url 'https://www.dynamsoft.com/Products/mobile-imaging-sdk.aspx'
developers {
developer {
id 'Dynamsoft'
name 'Dynamsoft'
email 'support@dynamsoft.com'
}
}
}
}
}
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
The URL file:\\DESKTOP-3PCHU10\site\ is a shared folder.
Add “apply from: ‘maven-publish.gradle’“ to the end of dcs\build.gradle.
Write some Java classes and methods.
Build and upload the AAR file to file:\\DESKTOP-3PCHU10\site\ by running the Gradle command.
Hosting Maven Repository on IIS
Create a website on IIS.
Add MIME types to web.config.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".aar" mimeType="application/java-archive" />
<mimeMap fileExtension=".pom" mimeType="text/xml" />
<mimeMap fileExtension=".md5" mimeType="text/plain" />
<mimeMap fileExtension=".sha1" mimeType="text/plain" />
</staticContent>
</system.webServer>
</configuration>
You may see the unauthorized error when browsing the website.
To fix the error, right-click the site folder and select security > edit to add everyone as a username.
Refresh your page. It should work now.
Download and run ngrok:
ngrok http 80
I got the randomly generated URL https://727eb58a.ngrok.io. When you restart ngrok, the URL will change.
Adding Dependency from Hosted Maven Repository in Android Project
Create an Android project maventest.
Configure my Maven repository in MavenTest\build.gradle.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven{
url 'https://727eb58a.ngrok.io'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Open app\build.gradle to add the dependency com.dynamsoft:dcs:1.0 (groupid:artifactid:version).
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.dynamsoft.maventest"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: \['\*.jar'\])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.dynamsoft:dcs:1.0'
}
The library is now available.
package com.dynamsoft.maventest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.dynamsoft.dcs.Camera;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
Camera camera = new Camera();
tv.setText(camera.getName());
setContentView(tv);
}
}