使用 maven 存储库将 java 库添加到 Android Studio 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22021970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add java library to Android Studio project with maven repository
提问by letiagoalves
I want to try this libraryin my android project. I am using Android Studio 0.4.6.
我想在我的 android 项目中尝试这个库。我正在使用Android Studio 0.4.6。
The README.markdownfile 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. 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.
问题是我没有任何 pom.xml。我在我的项目根目录中创建了一个并同步了 gradle 设置,但它什么也没做。到目前为止,我只使用已经编译好的 .jar 文件或使用 gradle 编译功能。
How can I use this library in my project?
如何在我的项目中使用这个库?
采纳答案by Scott Barta
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.gradlefile in your module's directory (not the build file in the project root directory).
Android Studio 不使用 Maven 作为其构建器;它使用 Gradle 代替。幸运的是,Gradle 可以使用 Maven 存储库来获取依赖项,因此只需将这些信息放入 pom 文件并以 Gradle 格式使用它即可。这些修改位于模块目录中的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>'