简体   繁体   English

Android:将外部库添加到项目中不起作用

[英]Android: Adding external library to project not working

I am trying to add Jsoup library to my project, but I am getting an error in the program saying "Cannot resolve symbol 'Jsoup'". 我试图将Jsoup库添加到我的项目中,但是程序中出现错误提示“无法解析符号'Jsoup'”。 Below is what I have done, but not working. 以下是我已经完成的工作,但无法正常工作。

1)From the Jsoup website, I downloaded the core library jsoup-1.10.2.jar 1)我从Jsoup网站下载了核心库jsoup-1.10.2.jar
2)Dragged and dropped the .jar file under libs folder in my project 2)将.jar文件拖放到我项目的libs文件夹下
3)Under build.gradle in dependencies, I added the following line 3)在build.gradle中的依赖项下,我添加了以下行

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

4)In MainActivity.java file, I tried to add the following line 4)在MainActivity.java文件中,我尝试添加以下行

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

Then, Jsoup turns red and says "Cannot resolve symbol 'Jsoup'". 然后,Jsoup变成红色,并说“无法解析符号'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. 但我收到此错误。

In the file build.gradle you should have the following: 在文件build.gradle您应该具有以下内容:

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

You can see the instructions here , in Gradle section. 您可以在此处的Gradle部分中查看说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM