Android:将外部库添加到项目中无法正常工作 [英] Android: Adding external library to project not working

查看:228
本文介绍了Android:将外部库添加到项目中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Jsoup库添加到我的项目中,但是程序中出现错误提示无法解析符号'Jsoup'".以下是我已经完成的工作,但是没有正常工作.

I am trying to add Jsoup library to my project, but I am getting an error in the program saying "Cannot resolve symbol 'Jsoup'". Below is what I have done, but not working.

1)我从Jsoup网站下载了核心库jsoup-1.10.2.jar
2)将.jar文件拖放到我的项目的libs文件夹下
3)在build.gradle中的依赖项下,我添加了以下行

1)From the Jsoup website, I downloaded the core library jsoup-1.10.2.jar
2)Dragged and dropped the .jar file under libs folder in my project
3)Under build.gradle in dependencies, I added the following line

compile files('libs/jsoup-1.10.2.jar')

4)在MainActivity.java文件中,我尝试添加以下行

4)In MainActivity.java file, I tried to add the following line

String url = "http://example.com";
try {
    Document document = Jsoup.connect(url).get();
    //more code here
}

然后,Jsoup变为红色并显示无法解析符号'Jsoup'". 谁能告诉我我在做什么错?我访问了许多网站,并观看了一些教程视频,然后我对其进行了跟踪.但是我遇到了这个错误.

Then, Jsoup turns red and says "Cannot resolve symbol 'Jsoup'". Can anyone tell me what I am doing wrong? I visited many websites and watched a few tutorial videos and I followed them. But I am getting this error.

推荐答案

在文件build.gradle中,您应该具有以下内容:

In the file build.gradle you should have the following:

dependencies {
    ...
    compile 'org.jsoup:jsoup:1.10.2'
    ...
}

您可以在Gradle部分的此处中查看.

You can see the instructions here, in Gradle section.

这篇关于Android:将外部库添加到项目中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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