C++ library for both 'desktop' and android with binary library dependencies

Hi,

I’d like to solve the following challenge.

I have a C++ library (my own source code), that depends on a native library, that I’d like to depend on in a binary compiled form. I’d like to create a gradle library project for my C++ library, that I can use both in a ‘dektop’ C++ app as a regular library, and also in an android project as a native (NDK) library.

suppose I have the following:

lib3rdparty
|-- include
|    |-- 3rdparty1.h
|    `-- 3rdparty2.h
`-- lib
      |-- linux-x86_84
      |    `-- lib3rdparty.so
      |-- macos-x86_84
      |    `-- lib3rdparty.so
      `-- android-arm7a
           `-- lib3rdparty.so

libmylibrary
|-- include
|    |-- mylibrary1.h
|    `-- mylibrary2.h
`-- src
      |-- mylibrary1.cpp
      `-- mylibrary2.cpp

mydesktopapp
|-- include
|    |-- mydesktopapp1.h
|    `-- mydesktopapp2.h
`-- src
      |-- mydesktopapp1.cpp
      `-- mydesktopapp2.cpp

myandroidapp
|-- java
|    `-- my
|          `-- android
|                `-- app
|                      `-- App.java
`-- cpp
    |-- include
    |    |-- mydesktopapp1.h
    |    `-- mydesktopapp2.h
    `-- src
          |-- mydesktopapp1.cpp
          `-- mydesktopapp2.cpp

where

libmylibrary depends on lib3rdparty

mydekstopapp depends on libmylibrary (and transitively depends on lib3rdparty)

myandroidapp depends on libmylibrary (and transitively depends on lib3rdparty)

how would one go about such a setup with gradle?

would one do all native compilation, etc. via cmake and let gradle run cmake?
or ‘within’ gradle itself?

Great question @darkeye and it’s possible to make it work but does require quite a few. We would love to remove this additional configuration for the future. The direction for prebuilt libraries is to create a project “producing” the binaries. The same can be done for projects using a separate build system such as CMake. For the latter, I suggest looking at CMake build wrapping sample.

For prebuilt binaries, the same process as the build wrapping would be done but simpler as you only need to expose the binaries to the dependency engine.

The “producing” project is a wide term to mean exposing the binaries to the dependency engine so they can participate to the dependency resolution. You can also use the producing project for fetching the binaries from another source such as a website or package manager.

I hope this makes sense. We were hoping to find some time soon and provide a sample for dealing with prebuilt binaries.