使用 maven 存储库将 java 库添加到 Android Studio 项目 [英] Add java library to Android Studio project with maven repository

查看:36
本文介绍了使用 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>'

这篇关于使用 maven 存储库将 java 库添加到 Android Studio 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆