简体   繁体   English

使用 maven 存储库将 java 库添加到 Android Studio 项目

[英]Add java library to Android Studio project with maven repository

I want to try this library in my android project.我想在我的 android 项目中尝试这个 I am using Android Studio 0.4.6 .我正在使用Android Studio 0.4.6

The README.markdown file tells me to insert this inside pom.xml : README.markdown文件告诉我将它插入到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 .问题是我没有任何 pom.xml I created one in my project root directory and synced gradle settings but it does nothing.我在我的项目根目录中创建了一个并同步了 gradle 设置,但它什么也没做。 Till now I only used already compiled .jar files or used the gradle compile function.到目前为止,我只使用已经编译好的 .jar 文件或使用 gradle 编译功能。

How can I use this library in my project?如何在我的项目中使用这个库?

Android Studio doesn't use Maven as its builder; Android Studio 不使用 Maven 作为其构建器; it uses Gradle instead.它使用 Gradle 代替。 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.幸运的是,Gradle 可以使用 Maven 存储库来获取依赖项,因此只需将这些信息放入 pom 文件并以 Gradle 格式使用它即可。 These modifications go in the build.gradle file in your module's directory (not the build file in the project root directory).这些修改位于模块目录中的build.gradle文件中(而不是项目根目录中的构建文件)。

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块来添加依赖项本身:

dependencies {
    ...
    compile 'io.socket:socket.io-client:0.2.1'
}

Update:更新:
From POM file:从 POM 文件:

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

Syntax: implementation 'groupId:artifactId:version'语法:实现 'groupId:artifactId:version'

If this is what you have to import in your Android Studio Project...如果这是您必须在 Android Studio 项目中导入的内容...

 // 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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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