0

I am having the following Android.mk file for my app which is using aar-release.aar

include $(CLEAR_VARS)

res_dir := res $(LOCAL_PATH)/res
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES += <...>
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dir))
LOCAL_USE_AAPT2 := true
LOCAL_JAVA_LIBRARIES := com.google.android.material_material \
LOCAL_STATIC_JAVA_LIBRARIES += aar-release

LOCAL_STATIC_ANDROID_LIBRARIES := \
        androidx.appcompat_appcompat \
        androidx-constraintlayout_constraintlayout \
        androidx.preference_preference \
        androidx.fragment_fragment \
        androidx.core_core \

LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PACKAGE_NAME := <My app>
LOCAL_PRIVATE_PLATFORM_APIS := true

LOCAL_RENDERSCRIPT_TARGET_API := 21
LOCAL_PROGUARD_FLAG_FILES   := proguard-project.txt

include $(BUILD_PACKAGE)


include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += aar-release:libs/aar-release.aar
include $(BUILD_MULTI_PREBUILT)

It is working fine but I have issues with licenses that require me not to link my library statically. I tried changing LOCAL_STATIC_JAVA_LIBRARIES += aar-release to LOCAL_JAVA_LIBRARIES := aar-release

which compiled successfully but got runtime error

E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: L<my class>$Runtime;

I also replaced LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES with LOCAL_PREBUILT_JAVA_LIBRARIES and got error

[ 99% 830/831] aar-release dexpreopt 
FAILED: out/target/product/<my product>/obj/JAVA LIBRARIES/aar-release_intermediates/dexpreopt.zip
dex2oatd E 06-08 06:05:08 20633 20633 oat writer.cc:568] No dex files in zip file '/system/framework/aar-release.aar': Entry not found 
error: out/target/product/<my product>/obj/JAVA_LIBRARIES/aar-release_intermediates/dexpreopt.sh:25 exited with status 1

How can I add to my preinstalled app in AOSP as a shared library my aar-release.aar which is a prebuilt library?

BTW, where can I find the full documentation for Android.mk? It should have all the fields like this one for Android.bp https://ci.android.com/builds/submitted/8520137/linux/latest/view/soong_build.html.

zeitgeist
  • 852
  • 12
  • 19
  • https://stackoverflow.com/questions/31205856/aar-support-in-android-mk – Yong Jun 09 '22 at 09:46
  • @Yong I wish to add my `.aar` library as a shared library not as a static library. – zeitgeist Jun 10 '22 at 16:49
  • Does the .aar file get installed in your target filesystem? It must be there to find the methods at run time. – Brent K. Aug 10 '22 at 13:05
  • BTW, I found a workaround as Java except some complex native calls has got only dynamic linking. This means static and shared libraries are both acceptable for licenses. – zeitgeist Aug 25 '22 at 13:31

0 Answers0