Missing CMake libs in APK

My Gradle file is building a CMake project that creates two libs, but only one is added to the APK. I know AGP can ‘see’ both the CMake targets and their file paths because they’re both listed in the generated android_gradle_build.json file:

"renderdoc::@febfabf0ba9bc1c41be4": {
  "toolchain": "toolchain",
  "abi": "arm64-v8a",
  "artifactName": "renderdoc",
  "output": "<staging dir>/Debug/<hash>/arm64-v8a/lib/libVkLayer_GLES_RenderDoc.so",
  "runtimeFiles": []
},
"renderdoccmd::@e4803fe6fd4d0c030575": {
  "toolchain": "toolchain",
  "abi": "arm64-v8a",
  "artifactName": "renderdoccmd",
  "output": "<staging dir>/Debug/<hash>/arm64-v8a/lib/librenderdoccmd.so",
  "runtimeFiles": [
    "<staging dir>/Debug/<hash>/lib/libVkLayer_GLES_RenderDoc.so"
  ]
}

And indeed the files are built in the locations listed. But in gradle/build/intermediates/cxx/Debug/<hash>/obj/arm64-v8a there is only the librenderdoccmd.so library, and subsequently only that lib ends up in the APK.

How does Gradle/AGP decide which CMake-generated files should be copied into the APK?

This is highly Android specific, might be worth asking in some Android community instead. :man_shrugging:

I’ve fixed the issue, and it wasn’t specific to Gradle or Android. Gradle places the CMake artifacts into the correct staging location after building by setting the CMAKE_LIBRARY_OUTPUT_DIRECTORY and CMAKE_RUNTIME_OUTPUT_DIRECTORY vars, however the top-level CMakeLists.txt in my project was overwriting these values.

1 Like