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.
You can base your solution on some other jar already added in AOSP.
For example see ZXING library's Android.bp in external/zxing/
:
java_import {
name: "zxing-core-1.7",
host_supported: true,
installable: false,
jars: ["core.jar"],
}
Then see the usage on another Makefile: :
LOCAL_STATIC_JAVA_LIBRARIES := \
androidx-constraintlayout_constraintlayout-solver \
androidx.lifecycle_lifecycle-runtime \
androidx.lifecycle_lifecycle-extensions \
guava \
jsr305 \
carsettings-contextual-card-protos-lite \
carsettings-log-bridge-protos-lite \
carsettings-logtags \
statslog-settings \
zxing-core-1.7
Lastly, based on the path of the file you're adding frameworks/base/services/core/java/com/android/server/am/sample.java
, you're adding the library to the wrong makefile.
The one you changed (frameworks/base/Android.mk
) is for making framework.jar
, whereas you're trying to add a class on services.jar
The correct makefile to modify would be: frameworks/base/services/core/Android.bp