Trying to make prebuilt binary library dependency transitive - but how?

Hi,

I’m trying to include a prebuilt library dependency into my project, based on the prebuilt-binaries example in native-samples: https://github.com/gradle/native-samples/tree/master/cpp/prebuilt-binaries

here is my take on the topic: https://github.com/akosmaroy/gradle-playground/tree/master/external-lib-sample

but it fails, as the external library binary files are not ‘carried over’ through the dependency chain:

git clone https://github.com/akosmaroy/gradle-playground.git
cd gradle-payground/external-lib-sample
cd external
./gradlew build
../theapp
./gradlew build

and I’d expect this to work. but this is what I get:

cd external/
$ ./gradlew build

BUILD SUCCESSFUL in 614ms
2 actionable tasks: 2 executed

$ cd ../theapp/
$ ./gradlew build

> Task :myapp:linkDebug FAILED
/usr/bin/ld: warning: libexternal.so, needed by /home/akos/src/gradle-playground/external-lib-sample/theapp/mylibrary/build/lib/main/debug/libmylibrary.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /home/akos/src/gradle-playground/external-lib-sample/theapp/mylibrary/build/lib/main/debug/libmylibrary.so: undefined reference to `getExternalHello[abi:cxx11]()'
collect2: error: ld returned 1 exit status


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':myapp:linkDebug'.
> A build operation failed.
      Linker failed while linking myapp.
  See the complete log at: file:///home/akos/src/gradle-playground/external-lib-sample/theapp/myapp/build/tmp/linkDebug/output.txt
   > Linker failed while linking myapp.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 690ms
4 actionable tasks: 4 executed

looking at the directory structure, indeed, the external library file, libexternal.so, is not ‘carried over’ to libmylibrary:

$ tree .
.
├── external
│   ├── build
│   │   ├── lib
│   │   │   └── main
│   │   │       └── debug
│   │   │           └── libexternal.so
│   │   ├── obj
│   │   │   └── main
│   │   │       └── debug
│   │   │           └── 7o4bm6kwb4cvb14rrd957us1j
│   │   │               └── external.o
│   │   └── tmp
│   │       ├── compileDebugCpp
│   │       │   ├── options.txt
│   │       │   └── output.txt
│   │       └── linkDebug
│   │           ├── options.txt
│   │           └── output.txt
│   ├── build.gradle
│   ├── gradle
│   │   └── wrapper
│   │       ├── gradle-wrapper.jar
│   │       └── gradle-wrapper.properties
│   ├── gradlew
│   ├── gradlew.bat
│   └── src
│       └── main
│           ├── cpp
│           │   └── external.cpp
│           ├── include
│           └── public
│               └── external.h
└── theapp
    ├── gradle
    │   └── wrapper
    │       ├── gradle-wrapper.jar
    │       └── gradle-wrapper.properties
    ├── gradlew
    ├── gradlew.bat
    ├── myapp
    │   ├── build
    │   │   ├── exe
    │   │   │   └── main
    │   │   │       └── debug
    │   │   ├── obj
    │   │   │   └── main
    │   │   │       └── debug
    │   │   │           └── c0rn65lkroj8p4fvz0qgmzzjr
    │   │   │               └── app.o
    │   │   └── tmp
    │   │       ├── compileDebugCpp
    │   │       │   ├── options.txt
    │   │       │   └── output.txt
    │   │       └── linkDebug
    │   │           ├── options.txt
    │   │           └── output.txt
    │   ├── build.gradle
    │   └── src
    │       └── main
    │           ├── cpp
    │           │   └── app.cpp
    │           └── headers
    │               └── app.h
    ├── mylibrary
    │   ├── build
    │   │   ├── lib
    │   │   │   └── main
    │   │   │       └── debug
    │   │   │           └── libmylibrary.so
    │   │   ├── obj
    │   │   │   └── main
    │   │   │       └── debug
    │   │   │           └── 9b7fb0ryo4gvfllswhexp447v
    │   │   │               └── mylibrary.o
    │   │   └── tmp
    │   │       ├── compileDebugCpp
    │   │       │   ├── options.txt
    │   │       │   └── output.txt
    │   │       └── linkDebug
    │   │           ├── options.txt
    │   │           └── output.txt
    │   ├── build.gradle
    │   └── src
    │       └── main
    │           ├── cpp
    │           │   └── mylibrary.cpp
    │           ├── include
    │           └── public
    │               └── mylibrary.h
    └── settings.gradle

55 directories, 35 files

if I add the directory holding libexternal.so to LD_LIBRARY_PATH, it will work:

$ export LD_LIBRARY_PATH=/home/akos/src/gradle-playground/external-lib-sample/external/build/lib/main/debug
$ cd theapp
$ ./gradelw build

BUILD SUCCESSFUL in 675ms
5 actionable tasks: 5 executed

interestingly, the dependency manager ‘carries over’ libmylibrary.so during the build process to theapp:

$ ls -l myapp/build/install/main/debug/lib/
total 132
-rwxr-xr-x 1 akos akos 61312 Jul  5 08:12 libmylibrary.so
-rwxr-xr-x 1 akos akos 70552 Jul  5 08:12 myapp

but libexternal.so is not ‘carried over’ in a similar fashion.

how would I achieve that libexternal.so is also ‘carried over’, so that the build completes successfully?

Akos