I wish to use jsoup library in Android Open Source Project. For this I did two things:-
Step 1:
[android]prebuilts/misc/common/jsoup/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:
Problem:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
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
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.
Based ENTIRELY upon Answer provided by @RickSanchez, I followed these steps as guided by his answer to bring up a successful build:
[android]prebuilts/misc/common/jsoup/jsoup folder, I included a blueprint file Android.bp and jsoup-1.13.1.jar downloaded from https://jsoup.org/downloadAndroid.bp talked above as follows:Android.bp
java_import {
name: "jsoup-1.13.1",
host_supported: true,
installable: false,
jars: ["jsoup-1.13.1.jar"],
}
Next task was to give ref of above created Local Blueprint file to Android.bp present in frameworks/base/services/core/Android.bp
To this, I made the following edit:
In Android.bp either add the following if present or modify the following block -
static_libs: [
"jsoup-1.13.1", /*use jsoup lib */
"android.hardware.authsecret-V1.0-java",
....
....
],
The build is now successful and the sample.java is successfully able to use jsoup library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With