Crosswind Crosswind - 3 months ago 12
Android Question

Build error and fatal exception using Jsoup

I want to use jsoup so I downloaded the jsoup-1.9.2.jar file and moved it in my libs folder in Android Studio. When I tried to build the project I get the following error:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.



com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/org.jsoup/jsoup/pom.xml
File1: /Users/David/AndroidStudioProjects/Vertretungsplan2/app/libs/jsoup-1.9.2.jar
File2: /Users/David/.gradle/caches/modules-2/files-2.1/org.jsoup/jsoup/1.9.2/5e3bda828a80c7a21dfbe2308d1755759c2fd7b4/jsoup-1.9.2.jar


I tried several things suggested all around Google. I excluded these files in the build.gradle:

exclude 'org/jsoup/nodes/entities-full.xml'
exclude 'org/jsoup/nodes/entities-full.properties'
exclude 'META-INF/maven/org.jsoup/jsoup/pom.xml'
exclude 'META-INF/maven/org.jsoup/jsoup/pom.properties'
exclude 'org/jsoup/nodes/entities-base.properties'
exclude 'org/jsoup/nodes/entities-base.xml'


This let Android Studio build the project successfully but whenever I try to use jsoup I get the following error:

08-14 18:52:53.852 8200-8906/de.gymnasium_beetzendorf.vertretungsplan E/AndroidRuntime: FATAL EXCEPTION: IntentService[RefreshService]
Process: de.gymnasium_beetzendorf.vertretungsplan, PID: 8200
java.lang.ExceptionInInitializerError
at org.jsoup.nodes.Entities.access$000(Entities.java:17)
at org.jsoup.nodes.Entities$EscapeMode.<clinit>(Entities.java:20)
at org.jsoup.nodes.Document$OutputSettings.<init>(Document.java:371)
at org.jsoup.nodes.Document.<init>(Document.java:18)
at org.jsoup.parser.TreeBuilder.initialiseParse(TreeBuilder.java:29)
at org.jsoup.parser.TreeBuilder.parse(TreeBuilder.java:42)
at org.jsoup.parser.HtmlTreeBuilder.parse(HtmlTreeBuilder.java:52)
at org.jsoup.parser.Parser.parseInput(Parser.java:30)
at org.jsoup.helper.DataUtil.parseByteData(DataUtil.java:136)
at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:653)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:217)
at de.gymnasium_beetzendorf.vertretungsplan.RefreshService.doStuff(RefreshService.java:252)
at de.gymnasium_beetzendorf.vertretungsplan.RefreshService.onHandleIntent(RefreshService.java:93)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: java.lang.NullPointerException: in == null
at java.util.Properties.load(Properties.java:246)
at org.jsoup.nodes.Entities.loadEntities(Entities.java:241)
at org.jsoup.nodes.Entities.<clinit>(Entities.java:225)
at org.jsoup.nodes.Entities.access$000(Entities.java:17) 
at org.jsoup.nodes.Entities$EscapeMode.<clinit>(Entities.java:20) 
at org.jsoup.nodes.Document$OutputSettings.<init>(Document.java:371) 
at org.jsoup.nodes.Document.<init>(Document.java:18) 
at org.jsoup.parser.TreeBuilder.initialiseParse(TreeBuilder.java:29) 
at org.jsoup.parser.TreeBuilder.parse(TreeBuilder.java:42) 
at org.jsoup.parser.HtmlTreeBuilder.parse(HtmlTreeBuilder.java:52) 
at org.jsoup.parser.Parser.parseInput(Parser.java:30) 
at org.jsoup.helper.DataUtil.parseByteData(DataUtil.java:136) 
at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:653) 
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:217) 
at de.gymnasium_beetzendorf.vertretungsplan.RefreshService.doStuff(RefreshService.java:252) 
at de.gymnasium_beetzendorf.vertretungsplan.RefreshService.onHandleIntent(RefreshService.java:93) 
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.os.HandlerThread.run(HandlerThread.java:61) 


I have no idea what I have to do to solve this so any help is appreciated. If my post is missing any information you guys need just let me know. Thanks!

Java code that uses jsoup:

public void doStuff () {
String url = "http://gymnasium-beetzendorf.de/uorganisation/vplan.html";

try {
Document document = Jsoup.connect(url).get();

Elements div = document.select("div.content");
Elements a = div.select("a");

Log.i(MainActivity.TAG, "anzahl der links " + String.valueOf(a.size()));
} catch (IOException e) {
e.printStackTrace();
}
}

Answer

Your Gradle error is stating there are duplicate files that are conflicting between the JAR file, and the compiled Gradle dependency, which you probably have this in your dependencies.

compile 'org.jsoup:jsoup:1.9.2'

Therefore, you shouldn't need to download a JAR file, or exclude anything, you can simply use that library.

Comments