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

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

问题描述:

我想在我的 android 项目中尝试这个 library.我使用的是 Android Studio 0.4.6.

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

README.markdown 文件告诉我将它插入到 pom.xml 中:

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>

问题是我没有任何 pom.xml.我在我的项目根目录中创建了一个并同步了 gradle 设置,但它什么也没做.到现在我只使用已经编译好的.jar文件或者使用gradle编译功能.

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 不使用 Maven 作为其构建器;它使用 Gradle 代替.幸运的是,Gradle 可以使用 Maven 存储库来获取依赖项,因此只需将这些信息放入 pom 文件并以 Gradle 格式使用它即可.这些修改位于模块目录中的 build.gradle 文件中(而不是项目根目录中的构建文件).

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

然后通过将此行添加到您的 dependencies 块中来添加依赖项本身:

and then add the dependency itself by adding this line to your dependencies block:

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

更新:
来自 POM 文件:

Update:
From POM file:

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