Android使用prefab方式构建aar时,引用方无法生成xxxConfig.cmake问题

473 阅读1分钟

假设模块A依赖模块B,A想使用B中的c层代码,而B以prefab方式构建:

android {
 ...
    buildFeatures {
        prefabPublishing true
    }
}

需要在A中:

android {
 ...
    buildFeatures {
        prefab true
    }
}

同时A的CMakeLists.txt中查找并链接B:

find_package(xxxx REQUIRED CONFIG)
target_link_libraries(A_NAME xxxx::xxxx)

这时编译可能会报错:

CMake Error at CMakeLists.txt:44 (find_package):
  Could not find a package configuration file provided by "xxxx" with any
  of the following names:
    xxxxConfig.cmake
    xxxx-config.cmake
  Add the installation prefix of "xxxx" to CMAKE_PREFIX_PATH or set
  "xxxx_DIR" to a directory containing one of the above files.  If "xxxx"
  provides a separate development package or SDK, be sure it has been
  installed.

解决这个报错需要确保A和B编译时使用的C STL保持一致,才会在A的编译目录.cxx自动生成xxxxConfig.cmake配置文件。

android {
 ...
    defaultConfig {
        externalNativeBuild {
            cmake {
                arguments '-DANDROID_STL=c++_shared'
            }
        }
    }
}