问题
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)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)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
}
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.
回答1:
In the file build.gradle
you should have the following:
dependencies {
...
compile 'org.jsoup:jsoup:1.10.2'
...
}
You can see the instructions here, in Gradle section.
来源:https://stackoverflow.com/questions/42146916/android-adding-external-library-to-project-not-working