# Android.bp support?

**URL:** https://discourse.cmake.org/t/android-bp-support/2231
**Category:** Development
**Created:** [November 24, 2020, 10:01pm UTC](https://discourse.cmake.org/t/android-bp-support/2231 "2020-11-24T22:01:19Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [November 24, 2020, 10:01pm UTC](https://discourse.cmake.org/t/android-bp-support/2231/1 "2020-11-24T22:01:19Z")

</div>

At work somewhat brought up maintaining a separate build system for Android.bp along with our current cmake build system.

This is the first time I heard of Android.bp, we have been using cmake for Android for a while.

Could/can cmake just generate the Android.bp files?  
Either as a generator or install step? ([https://gitlab.kitware.com/cmake/cmake/-/issues/15562](https://gitlab.kitware.com/cmake/cmake/-/issues/15562))

I really don’t want to have to maintain 2 build systems…

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 24, 2020, 10:19pm UTC](https://discourse.cmake.org/t/android-bp-support/2231/2 "2020-11-24T22:19:13Z")

</div>

This is the first time I’ve heard about `Android.bp`. It looks like Make-ish? I believe that Android will be supporting CMake through hooks where they provide the guts and CMake the hooks that need to be implemented. Support for `Android.bp` would need to be investigated as to whether `export()` or a generator would be a better solution.

Cc: @kyle.edwards @brad.king

---

<div class="post-metadata">

### Author: ![mwezdeck](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/b5e925/32.png) [@mwezdeck](https://discourse.cmake.org/u/mwezdeck)
#### Post date: [November 25, 2020, 7:46am UTC](https://discourse.cmake.org/t/android-bp-support/2231/3 "2020-11-25T07:46:23Z")

</div>

`Android.bp` is declarative JSON file without control flow or conditionals at all. In addition to `Android.bp` advanced build systems often implement GO modules for handling control flow. Android build system parses `Android.bp` + compiles GO modules, then it produces Kati files, which then are producing Ninja files.

If Cmake can generate Android.bp files, it is the best solution for software, where Android, Linux and Windows must be supported.

For more information, please read this pages:

> **[platform/build/soong - Git at Google](https://android.googlesource.com/platform/build/soong/)**

  

> **[Build Performance](https://android.googlesource.com/platform/build/soong/+/refs/heads/master/docs/perf.md)**

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [November 25, 2020, 12:27pm UTC](https://discourse.cmake.org/t/android-bp-support/2231/4 "2020-11-25T12:27:04Z")

</div>

> or install step?

Something like [`install(EXPORT_ANDROID_MK)`](https://cmake.org/cmake/help/v3.19/command/install.html#installing-exports) could be added for this.

---

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [November 25, 2020, 8:04pm UTC](https://discourse.cmake.org/t/android-bp-support/2231/5 "2020-11-25T20:04:59Z")

</div>

@brad.king perhaps something like install(EXPORT\_ANDROID\_BP) is the solution.

I work with @mwezdeck so they can clarify if something like that is an acceptable solution for us.

(@mwezdeck knows more about building for Android than I do, I’m the Windows/Linux guy)

---

<div class="post-metadata">

### Author: ![mwezdeck](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/b5e925/32.png) [@mwezdeck](https://discourse.cmake.org/u/mwezdeck)
#### Post date: [November 26, 2020, 8:33am UTC](https://discourse.cmake.org/t/android-bp-support/2231/6 "2020-11-26T08:33:16Z")

</div>

Quote:

> The `EXPORT` form is useful to help outside projects use targets built and installed by the current project. For example, the code

```
install(TARGETS myexe EXPORT myproj DESTINATION bin) 
install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj) 
install(EXPORT_ANDROID_MK myproj DESTINATION share/ndk-modules)

```

> will install the executable `myexe` to `<prefix>/bin` and code to import it in the file `<prefix>/lib/myproj/myproj.cmake` and `<prefix>/share/ndk-modules/Android.mk` . An outside project may load this file with the include command and reference the `myexe` executable from the installation tree using the imported target name `mp_myexe` as if the target were built in its own tree.

I’m not quite sure about this solution. Why do we need `<prefix>/lib/myprij/myproj.cmake` at all? Can we use ` <prefix>/share/ndk-modules/Android.mk` as standalone Makefile, I mean without `<prefix>/lib/myprij/myproj.cmake`?

If the answer is yes, then `install(EXPORT_ANDROID_BP)` is the solution we are looking for.

I have only one concern here.

Android.bp doesn’t have “if” statements at all. All control flow logic is implemented in GO-lang modules which come in parrallel to Android.bp. How this can be handled?

If the answer is no, then this solution is not proper for us, as building with NDK and cmake toolchain under Android seems to take more time, than “native” Android.bp solution, especially when we are compiling both x86 and x86\_64 shared libraries.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 26, 2020, 1:55pm UTC](https://discourse.cmake.org/t/android-bp-support/2231/7 "2020-11-26T13:55:58Z")

</div>

I think the `Android.mk` file is standalone (it is Makefile code, so how it would use the `.cmake` file, I’m not sure). The details of how we write `.bp` files would need to be investigated, but CMake would probably just write “here is where the install put things” and they can be used as necessary.

---

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [December 3, 2020, 5:18pm UTC](https://discourse.cmake.org/t/android-bp-support/2231/8 "2020-12-03T17:18:58Z")

</div>

To be 100% clear here the problem isn’t building for Android.  
The problem is building for AOSP (Android Open Source Project).

This stackoverflow question says it quite concisely:

> <https://stackoverflow.com/questions/43679347/include-cmake-project-in-aosp-build>

Dan Albert a Google/Android engineer from the looks of it comments that:  
“It is not possible to build cmake projects in the AOSP build system.”

And this is the problem we are looking to solve. Anything that can fix this problem is the solution we need from cmake. What would it take to achieve this?

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [January 24, 2023, 11:37pm UTC](https://discourse.cmake.org/t/android-bp-support/2231/9 "2023-01-24T23:37:35Z")

</div>

FWIW to anyone the way we handled this at my old company was just have `Android.bp` invoke CMake under the hood.

`Android.bp` was flexible enough to be able to build CMake transparently for the user.

Which satisfied `AOSP` and made our engineers happy since they just had to deal with CMake for the most part.

---

<div class="post-metadata">

### Author: ![Lukasz\_Tyrala](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lukasz_tyrala/32/1216_2.png) [@Lukasz\_Tyrala](https://discourse.cmake.org/u/Lukasz_Tyrala)
#### Post date: [February 23, 2024, 9:04pm UTC](https://discourse.cmake.org/t/android-bp-support/2231/10 "2024-02-23T21:04:03Z")

</div>

can you share some examples? how did you deal with the toolchain?
