如何在 Android Studio/IntelliJ 中导入 Maven 依赖项? [英] How to import Maven dependency in Android Studio/IntelliJ?

查看:49
本文介绍了如何在 Android Studio/IntelliJ 中导入 Maven 依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Android Studio 中的默认向导创建了一个新的 Android 项目.编译并将应用程序部署到我的设备.一切都很好.

现在我想导入一个在 Maven 上可用的外部库.(

I've created a new Android project using the default wizard in Android Studio. Compiled, and deployed the app to my device. All is well.

Now I want to import an external library that is available on Maven. (http://square.github.io/picasso/). I went to module properties, and added a Maven library. It shows up correctly in the list of dependencies. In addition, it shows up in the editor and I can correctly use it in code.

However, at compile time, I get a Gradle error: unable to find class

Any ideas?

解决方案

As of version 0.8.9, Android Studio supports the Maven Central Repository by default. So to add an external maven dependency all you need to do is edit the module's build.gradle file and insert a line into the dependencies section like this:

dependencies {

    // Remote binary dependency
    compile 'net.schmizz:sshj:0.10.0'

}

You will see a message appear like 'Sync now...' - click it and wait for the maven repo to be downloaded along with all of its dependencies. There will be some messages in the status bar at the bottom telling you what's happening regarding the download. After it finishes this, the imported JAR file along with its dependencies will be listed in the External Repositories tree in the Project Browser window, as shown below.

Some further explanations here: http://developer.android.com/sdk/installing/studio-build.html

这篇关于如何在 Android Studio/IntelliJ 中导入 Maven 依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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