My prefab contains no binaries or includes

Viewed 241

prefab runs successfully, but my resulting prefab directory only has CMake files in it, no other assets. My goal is to easily share binary assets with colleagues and include them in my Android builds. What am I doing wrong?

I'm attempting to create a prefab of boost (though google might make one if it gets enough votes). I used Boost-for-Android to build boost 1.73.0, copied the relevant includes and libraries out into an assembly directory, populated it with prefab.json, module.json, and abi.json files, and ran

prefab --output "/home/developer/workspace/boost-prefab/out/boost/x86_64" \
  --build-system cmake        \
  --platform     android      \
  --abi          "x86_64"     \
  --os-version   "21"         \
  --ndk-version  "21"         \
  --stl          "c++_static" \
  "/home/developer/workspace/boost-prefab/assembly/boost"

But the resulting directory only contains two CMake files per abi.

 $ find x86_64 -type f
 x86_64/lib/x86_64-linux-android/cmake/boost/boostConfig.cmake
 x86_64/lib/x86_64-linux-android/cmake/boost/boostConfigVersion.cmake

The assembly directory I created looks like (I followed the prefab structure prescribed in the docs):

boost/prefab.json
      modules/filesystem/
                         module.json
                         include/boost/...
                         libs/android.x86_64/
                                             abi.json
                                             libboost_filesystem.a
     modules/system/
                    module.json
                    include/boost/...
                    libs/android.x86_64/
                                        abi.json
                                        libboost_system.a

prefab.json:

{"schema_version": 1, "name": "boost", "version": "1.73.0", "dependencies": []}

modules/filesystem/module.json:

{"library_name": "libboost_filesystem"}

modules/filesystem/libs/android.x86_64/abi.json:

{"abi": "x86_64", "api": 21, "ndk": "21", "stl": "c++_static"}

I'll admit I'm confused about prefab's os-version, from what I can tell it's simply the NDK version (because it's not the API version or Android major version number), but I don't think that that's the problem.

I also tried to generate a boost prefab via vcpkg, but boost won't build in vcpkg right now (there are some PRs to address this, but I couldn't get it building.) In any case, vcpkg's example shows a slightly different layout as well where an AAR was inserted into the prefab.

My goal is to have a prebuilt archive of boost that's easy to my colleagues to import into their Android projects.

  • Am I simply misunderstanding what a prefab file is for?
  • The CMake files that do get generated seem primitive even compared to the default boost ones, i.e. I'd prefer the boost CMake files to the prefab ones being created here
  • Should I instead be trying to create an AAR for boost first?

End of the day, the only way I was able to use Boost in my Android project was to include its build in my CMAKE_FIND_ROOT_PATH, but if it comes down to this what's the advantage of prefab? I feel I might as well just integrate conan into my gradle build.

1 Answers

Am I simply misunderstanding what a prefab file is for?

Based on your next question, only slightly. It is a system for distributing prebuilt libraries in a build system agnostic manner. Aside from "build system agnostic", that lines up with what you're trying to do.

The CMake files that do get generated seem primitive even compared to the default boost ones, i.e. I'd prefer the boost CMake files to the prefab ones being created here

Prefab was designed to support arbitrary build systems without the need for that package author to care about supporting each individually. This is important for Android because while the plurality of people use CMake, ndk-build is also an officially supported option, and dozens of other build systems are also regularly used.

What features are you missing that would be provided by boost's own CMake files? Can file a feature request at https://github.com/google/prefab/issues if it's something that we can do in a build-system agnostic manner.

If it can't be described in a build system agnostic manner, Prefab isn't a good fit. vcpkg might be a better choice for that.

Should I instead be trying to create an AAR for boost first?

That's the easiest way to do use prefab packages from AGP, yeah. vcpkg is generally the easiest path to that given the existing corpus, but as you noted you'll need to send them a patch (or a bug report) to get their build fixed first.

Alternatively, https://android.googlesource.com/platform/tools/ndkports/ is how we build the handful that we currently publish. Should be easy to check out, add your own port file, and build your AAR. If you send us the patch I'll likely merge it when I've gotten the test infrastructure up and running (currently we can't contend with supporting many packages because testing is manual).

End of the day, the only way I was able to use Boost in my Android project was to include its build in my CMAKE_FIND_ROOT_PATH, but if it comes down to this what's the advantage of prefab?

You don't need to do that if you use an AAR. AGP handles the details for you if you do that. The intended use case is for build systems to integrate prefab, not for users to have to do the work. AGP already does that, but only when consuming from an AAR.

Related