Android: Adding external library to project not working

怎甘沉沦 提交于 2020-01-06 23:46:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!