Build AAR package as part of AOSP build

7,010 views
Skip to first unread message

adhiti

unread,
Mar 31, 2016, 10:48:14 AM3/31/16
to Android Building
Need information on building AAR package using AOSP build. What are the changes required in Android.mk to build AAR package?

For Ex: for static JAR we have include $(BUILD_STATIC_AAR_LIBRARY)
 to build static JAR.

Ying Wang

unread,
Apr 1, 2016, 1:03:45 PM4/1/16
to Android Building
The build system automatically sets up rule to build .aar when you  include $(BUILD_STATIC_AAR_LIBRARY) and the library has LOCAL_RESOURCE_DIR.
But it's not built by default. You need to run something like "make out/target/common/obj/JAVA_LIBRARIES/<library_name>_intermediates/javalib.aar to get it built.
 

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

satyanarayana Murthy desala

unread,
Aug 21, 2016, 4:55:51 PM8/21/16
to Android Building
Hi Adhiti,

I am also trying to build a module as AAR in AOSP build, Can you help me by sharing the mk file to achieve my task


Regards
Murthy

erik.gil...@gmail.com

unread,
Apr 25, 2017, 11:15:11 PM4/25/17
to Android Building
Hi,

Can you please elaborate your answer? I failed to build an AAR with the instructions in your post/commit.

Regards
Erik

rajesh khetan

unread,
Apr 26, 2017, 10:36:20 AM4/26/17
to Android Building
Not able to build aar using $(BUILD_STATIC_AAR_LIBRARY) . Can you please post your Android.mk 


On Thursday, March 31, 2016 at 8:18:14 PM UTC+5:30, adhiti wrote:

Ankit Bhargava

unread,
Sep 4, 2017, 10:57:47 AM9/4/17
to Android Building
Do you able to build AAR package using AOSP build? is it possible to do so?

kush singh

unread,
Nov 17, 2017, 8:28:40 AM11/17/17
to Android Building
To build the AAR file from the AOSP build, you need to make the Android.mk file for the that lib like below:-


LOCAL_PATH := $(call my-dir)
include $
(CLEAR_VARS)

LOCAL_SDK_VERSION
:= current
LOCAL_MODULE_TAGS
:= optional

LOCAL_MODULE := YourLibName

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
:= name_of_any_aar_lib_your_using_your_lib

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 package_name_of_any_aar_lib_your_using_your_lib


LOCAL_JACK_ENABLED
:= disabled
LOCAL_PROGUARD_ENABLED
:= disabled

include $(BUILD_STATIC_JAVA_LIBRARY)
##################################################
include $
(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES
:= prebuild_libs_if_any


include $
(BUILD_MULTI_PREBUILT)

include $
(call all-makefiles-under,$(LOCAL_PATH))

you need to use include $(BUILD_STATIC_JAVA_LIBRARY) instead of include $(BUILD_STATIC_AAR_LIBRARY) it worked for me
and save this make file with name Android.mk in you module, then to build use below command

make YourLibName out/target/common/obj/JAVA_LIBRARIES/YourLibName_intermediates/YourLibName.aar

Sebotor

unread,
Jan 18, 2018, 12:16:24 PM1/18/18
to Android Building
Hello,
I might be NOT understanding something...
Did anyone tried this yet or was successful on building aar library within the AOSP, which can be reused by other apps in the tree?  
I had been trying to build my custom aar library in the AOSP build for several weeks, but it doesn't work.  

1. With the "make YourLibName out/target/common/obj/JAVA_LIBRARIES/YourLibName_intermediates/YourLibName.aar", it gives me the following error
Starting build with ninja
ninja: Entering directory `.'
ninja: error: unknown target 'out/target/common/obj/JAVA_LIBRARIES/YourLibName_intermediates/YourLibName.aar'
make: *** [ninja_wrapper] Error 1

2. The only thing that works are the following commands
- In the the Library directory:
mm
- In the main directory:
make YourLibName

3. After the build, the following files get produced

in-out/target/poroduct/.../obj/JAVA_LIBRARIES/YourLibName_intermediates/
total 5668
rw-rw-r-- 1 sebotor sebotor 2428 Jan 18 07:45 javalib.jar
in-out/target/common/obj/JAVA_LIBRARIES/YourLibName_intermediates/
total 6064
drwxrwxr-x 4 sebotor sebotor   4096 Jan 18 07:45 classes
-rw-rw-r-- 1 sebotor sebotor   2428 Jan 18 07:45 classes-full-debug.jar
-rw-rw-r-- 1 sebotor sebotor   2428 Jan 18 07:45 classes.jar
-rw-rw-r-- 1 sebotor sebotor   2428 Jan 18 07:45 classes-jarjar.jar
-rw-rw-r-- 1 sebotor sebotor   2428 Jan 18 07:45 javalib.jar
-rw-rw-r-- 1 sebotor sebotor   3930 Jan 18 07:45 proguard_options
-rw-rw-r-- 1 sebotor sebotor 385622 Jan 18 07:45 public_resources.xml
drwxrwxr-x 4 sebotor sebotor   4096 Jan 18 07:45 src

According to the google docs, even if the aar (or zip) is not created and the files are in those directories, I would hope to see something that resembles the documentation:

Am I missing something or mis-understading?  Please let me know.

Thank you,

Sebotor

Tony Guo

unread,
Jun 4, 2018, 10:01:32 AM6/4/18
to Android Building
Hi, 

Instead of  make YourLibName out/target/common/obj/JAVA_LIBRARIES/YourLibName_intermediates/YourLibName.aar Could you please try

make YourLibName out/target/common/obj/JAVA_LIBRARIES/YourLibName_intermediates/javalib.aar

at least, it works on my AOSP build environment.

Kind regards,
Tony

Sebastian Tomaszewski

unread,
Jun 5, 2018, 1:02:27 PM6/5/18
to android-...@googlegroups.com
Hello Tony,
Thanks for the reply.  

I am NOT sure on whether or NOT that it works.  The problem that I had seen last June was related to the build environment that I am having with the AOSP tree.  Unfortunately I am stuck right now, because I can't update it (for various reasons).  Saying this, I found other work around this, by using other way to the things that I wanted to do.

Thanks,


Sebo

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-building@googlegroups.com

To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to a topic in the Google Groups "Android Building" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-building/htNXz9Lkq7E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-building+unsubscribe@googlegroups.com.

Vaibhav Shinde

unread,
Aug 25, 2018, 6:02:31 PM8/25/18
to Android Building
Hi Tony,

With these instruction I was able to build aar library using Android.mk, but how can we make aar library with Android.bp ?

Thanks,
Vaibhav

Ray

unread,
Jan 28, 2019, 6:26:43 PM1/28/19
to Android Building
Hi Tony,

It worked with your solution, I could get aar by using this command.  it seems it didn't work when I imported this aar into android studio. In my aar, I imported another jar by using 
include packages/services/xxx/xxx-lib/xxx.mk in my aar make file

This xxx.mk included support-annotations library, my app included implementation 'com.android.support:appcompat-v7', appcompat-v7 also included support-annotations. when I build it, I got below error:

AGPBI: {"kind":"error","text":"Program type already present: android.support.annotation.Dimension","sources":[{}],"tool":"D8"}

Do you guys know how to fix this kind of issue?

implementation(name:'mysdk', ext:'aar'){
exclude group: 'com.android.support', module:'support-annotations'
}

Unfortunately, it didn't work. Any suggestion for this error?

Thanks,
Ray
Reply all
Reply to author
Forward
0 new messages