1

As described in title.

I have created an android library with a module that generates a prefab.

   buildFeatures 
       {
            prefabPublishing true
        }

        prefab {
            functions {
                headers "src/main/cpp/functions"
            }
            calculator {
                headers "src/main/cpp/calculator"
            }
        }

The generated AAR does include a Prefab folder with the includes files and libraries. However, I see that the prefab.json and module.json are empty.

prefab.json

{
  "name": "mylibrary",
  "schema_version": 2,
  "dependencies": []
}

module.json

{
  "export_libraries": [],
  "android": {}
}

Do I have to edit these metadata myself inside the AAR file directly? Or some settings in CMAKE or Gradle will allow me to autofill these information?

Currently, the project that imports this AAR file is unable to detect these libraries. The find_package() is unable to find my libraries. My suspicion is that it is related to these metadata.

I've seen many people are still writing gradle tasks to unzip files, and manually import *.so and *.h files directly in CMAKE. If this is still the case, then then the prefab is not working as intended.

Kah Wai Lee
  • 127
  • 1
  • 2
  • 11

3 Answers3

0

i have same issue. and my tarket apk has error.

Could not find a package configuration file provided by "mylibrary" with any of the following names myLibraryConfig.cmake myLibrary-config.cmake

These files were not created in the prefab directory.

0

After reading through a bunch of github issues, I finally figured it out. Several things to check for when consuming a prefab native library:

1) Enable prefab in the dependency

Whatever project consumes your AAR, make sure you have prefab enabled there as well:

android {
...
    buildFeatures {
        prefab true
    }
}

2) Consistent STL

The C STL must be consistent across both the builder of the AAR and the consumer. In my case, I am using a shared STL, so both the builder and the consumer, have the following in their build.gradle:

android {
    compileSdk XX

    defaultConfig {
        ...
        externalNativeBuild {
            cmake {
                ...
                arguments '-DANDROID_STL=c++_shared'
            }
        }
    }
}
Nebel22
  • 478
  • 8
  • 17
0

There is a feature request, "Allow prefab module metadata to be set from AGP", which aims to auto-fill module.json for prefab modules.

If you are impacted, you might want to upvote that FR.

l33t
  • 18,692
  • 16
  • 103
  • 180