I wish to use jsoup library in Android Open Source Project. For this I did two things:-
Step 1:
- Made a directory jsoup in common as follows:
[android]prebuilts/misc/common/jsoup/
- In this jsoup folder I added jsoup-1.13.1.jar downloaded from : https://jsoup.org/download
- In this same jsoup folder I added another file
Android.mk
{as it is name and code below:}
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jsoup
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := jsoup-1.13.1.jar
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
LOCAL_DEX_PREOPT := false
include $(BUILD_PREBUILT)
Step 2:
- Go to another make file as follows : [android]/frameworks/base/Android.mk
- In this Android.mk file I added following line shown below (after the LOCAL_JAVA_LIBRARIES variable is set): LOCAL_STATIC_JAVA_LIBRARIES += jsoup
Problem:
- I have added a file sample.java as follows- [android]frameworks/base/services/core/java/com/android/server/am/sample.java
- In this sample.java file I have import statements as follows-
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
- When I build this whole modified android code, I get the following error and the build fails:
frameworks/base/services/core/java/com/android/server/am/sample.java:48: error: package org.jsoup does not exist
frameworks/base/services/core/java/com/android/server/am/sample.java:49: error: package org.jsoup.nodes does not exist
frameworks/base/services/core/java/com/android/server/am/sample.java:50: error: package org.jsoup.select does not exist
- I even tried using a method mentioning Android.bp instead of Android.mk but same build error.
- Also I am confused in naming of jar file as import statement includes org.jsoup... but jar file itself is just jsoup. (Do I have to change import statement like import jsoup ... or change name of jar file to org.jsoup...)
- Any other method other than involving Android.mk or Android.bp is also highly acceptable.
Please, I have no idea of including external jar files in AOSP. The code works fine locally in IntelliJ IDE Java otherwise. Any help is deeply appreciated. Thanks in advance.