添加Java库到Android Studio项目与Maven仓库仓库、项目、Android、Java

2023-09-05 10:13:40 作者:爷单身却潇洒

我想试试这个库在我的Andr​​oid项目。我使用的 Android的工作室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 。我在我的项目的根目录并同步摇篮设置创建一个,但它什么都不做。到现在我只用已经编译好的.jar文件或使用的摇篮编译功能。

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的工作室不使用Maven作为它的建造者;它采用摇篮代替。幸运的是,摇篮可以使用Maven仓库获取依赖关系,所以它的服用这些信息将进入POM文件和摇篮格式使用它的问题。这些修改去在 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 {
    ...
    compile 'io.socket:socket.io-client:0.2.1'
}