Using AOSP-Bazel to build external and vendor libs

744 views
Skip to first unread message

Joshua Puerta

unread,
Jun 16, 2023, 12:47:39 PM6/16/23
to Android Building
Hi Android Build group,

I hope this is the proper group to ask the question. Long story short, I'd like to know if it's possible to build projects contained in external and vendor directories using AOSP's Bazel. I read that is possible to build kernels (Kleaf) but it was futile for me to build some external and custom libs with it (even if I can build them using bazel in non-AOSP context).

In case that it's already supported, I'd like to know which modifications need to be done (or directly how to do it properly). Any tip and/or link to some repo/doc is more than welcomed.

In case that it's not yet supported, I'd like to know if it's included in the roadmap, and if we are far away from it.

For more context, we are trying to build a modified version of Tensorflow Lite lib. So far we are able to build it using CMake and the NDK, and include it somehow. As TFLite supports Bazel, we wanted to build it properly inside AOSP rather than including precompiled libs. I also found that there is a Tensorflow project in /external with several Android Blueprint files, which I guess I can port somehow to our TFLite, but I'd prefer to keep the same build system to minimize efforts.

Thanks for your time and best regards,

Extra ball: Is there any priority/control when selecting a build system for a project? If project X contains .mk, .bp and BUILD files, which system is going to be used? Bazel > Soong > .mk?




Kenny

unread,
Jul 6, 2023, 11:38:05 AM7/6/23
to Android Building
I've done something similar recently. 

Essentially, Android NDK is not exactly the same as the AOSP soong build system. To use bazel to build a library for AOSP, I had to bent Android NDK a little bit.

These involve the following steps:

1. Change __config so it uses __ instead of __ndk for _LIBCPP_ABI_NAMESPACE so it matches with AOSP
2. Update NDK's libc.a, libc++_static.a, and libc++_shared.so with the one in AOSP
3. Uses the existing android_binary project to build an apk with jni so it links the .so files for you. You then can find the .so files in the intermediate directory in Bazel-out.

Then, you can includes the .so files by using cc_prebuilt_library_shared in an Android.bp file.

Reply all
Reply to author
Forward
0 new messages