简体   繁体   中英

Add java library to Android Studio project with maven repository

I want to try this library in my android project. I am using Android Studio 0.4.6 .

The README.markdown file tells me to insert this inside pom.xml :

<!-- in the 'repositories' section -->
<repository>
  <id>keytwo.net</id>
  <name>Keytwo.net Repository</name>
  <url>http://audiobox.keytwo.net</url>
</repository>

<!-- in the 'dependencies' section -->
<dependency>
  <groupId>io.socket</groupId>
  <artifactId>socket.io-client</artifactId>
  <version>0.2.1</version> <!-- the desidered version -->
</dependency>

The problem is that I do not have any pom.xml . I created one in my project root directory and synced gradle settings but it does nothing. Till now I only used already compiled .jar files or used the gradle compile function.

How can I use this library in my project?

Android Studio doesn't use Maven as its builder; it uses Gradle instead. Fortunately, Gradle can use Maven repositories to fetch dependencies, so it's a matter of taking that information that would go into the pom file and using it in Gradle format. These modifications go in the 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'
}

Update:
From POM file:

compile '<groupId>:<artifactId>:<version>'

Syntax: implementation 'groupId:artifactId:version'

If this is what you have to import in your Android Studio Project...

 // Maven : Add these dependecies to your pom.xml (java6+) // <dependency> // <groupId>org.glassfish.jersey.core</groupId> // <artifactId>jersey-client</artifactId> // <version>2.8</version> // </dependency> // <dependency> // <groupId>org.glassfish.jersey.media</groupId> // <artifactId>jersey-media-json-jackson</artifactId> // <version>2.8</version> // </dependency>

then it translates to this...

 implementation 'org.glassfish.jersey.core:jersey-client:2.8' implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:2.8'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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