To build .aar from AOSP build system, you need to create the make file for your library,
Suppose you want to create lib named xyz.aar whose package name is com.xyz.xyz and internally your lib is using some other aar named abc.aar with package name com.abc.abc then the make file may look like below:-
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := xyz
LOCAL_STATIC_JAVA_LIBRARIES :=android-common \
android-support-v4 \
android-support-design \
android-support-v7-appcompat \
android-support-design-res \
android-support-v7-cardview
LOCAL_STATIC_JAVA_AAR_LIBRARIES:= abc
LOCAL_SRC_FILES := $(call all-java-files-under, java)
res_dirs := res \
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs)) \
prebuilts/sdk/current/support/v7/cardview/res \
prebuilts/sdk/current/support/v7/appcompat/res \
prebuilts/sdk/current/support/design/res \
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.v7.cardview \
--extra-packages android.support.v7.appcompat \
--extra-packages android.support.design \
--extra-packages com.abc.abc
LOCAL_JACK_ENABLED := disabled
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_STATIC_JAVA_LIBRARY)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := all_static_libs
include $(BUILD_MULTI_PREBUILT)
include $(call all-makefiles-under,$(LOCAL_PATH))
In above make file instead of using include $(BUILD_STATIC_AAR_LIBRARY) use include $(BUILD_STATIC_JAVA_LIBRARY) and set the aar lib name in variable LOCAL_MODULE
To compile the make file use below command
> make xyz out/target/common/obj/JAVA_LIBRARIES/xyz_intermediates/xyz.aar
Your xyz.aar will be at location out/target/common/obj/JAVA_LIBRARIES/xyz_intermediates/xyz.aar