Add java library to Android Studio project with maven repository
Source: StackOverflow, Quora, StackOverflow
Question: Add java library to Android Studio project with maven repository?
Answer: These modifications go in the build.gradle file in your module's directory (not the build file in the project root directory).
First, set up the repository where it can find the dependency.
repositories {
maven { url 'http://audiobox.keytwo.net' }
}
and then add the dependency itself by adding this line to your dependencies
block:
dependencies {
...
compile 'io.socket:socket.io-client:0.2.1'
}
For example, we have this Xuggle library with pom.xml look like this:
<project>
...
<repositories>
...
<repository>
<id>xuggle repo</id>
<url>http://xuggle.googlecode.com/svn/trunk/repo/share/java/</url>
</repository>
...
</repositories>
...
<dependencies>
...
<dependency>
<groupId>xuggle</groupId>
<artifactId>xuggle-xuggler</artifactId>
<version>5.2</version>
</dependency>
...
</dependencies>
...
</project>
Then in build.gradle we modify it like this:
apply plugin: 'com.android.application'
repositories {
maven {
url "http://xuggle.googlecode.com/svn/trunk/repo/share/java/"
}
}
dependencies {
compile group: 'xuggle', name: 'xuggle-xuggler', version: '5.2'
}
In case of authentication:
repositories {
mavenCentral()
maven {
credentials {
username xxx
password xxx
}
url 'http://mymaven/xxxx/repositories/releases/'
}
}