android - 无法为不是由该项目构建的目标指定链接库

标签 android c++ firebase cmake

我正在关注 this在我的 android 项目中使用 C++ 添加 firebase 的教程,我使用的是 CMake 版本 3.10.2 当我运行项目时,出现以下错误:

Error configuring CMake server
(C:\Users\User\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin).
Check for working C compiler:
C:/Users/User/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
Check for working C compiler:
C:/Users/User/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- works Detecting C compiler ABI info Detecting C compiler ABI info - done Detecting C compile features Detecting C compile features - done
Check for working CXX compiler:
C:/Users/User/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
Check for working CXX compiler:
C:/Users/User/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
-- works Detecting CXX compiler ABI info Detecting CXX compiler ABI info - done Detecting CXX compile features Detecting CXX compile
features - done Found PkgConfig:
C:/ProgramData/chocolatey/bin/pkg-config.exe (found version "0.28") 
CMake Error at CMakeLists.txt:52 (target_link_libraries):   Cannot
specify link libraries for target "firebase_analytics;firebase_app"  
which is not built by this project.


Configuring incomplete, errors occurred!

我的 CMakeLists.txt 文件:

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
        native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        native-lib.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
        native-lib

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})
# Add Firebase libraries to the target using the function from the SDK.
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)


# The core Firebase library (firebase_app) is required to use any Firebase product,
# and it must always be listed last.
set(firebase_libs firebase_analytics firebase_app)
target_link_libraries(${target_name} "${firebase_libs}")

最佳答案

这也可能是由于未首先列出您的 图书馆造成的。例如,如果你有这个:

add_library( my_native_code
             SHARED

             # Other stuff here
             )

target_link_libraries(
    android)

这将失败:

Cannot specify link libraries for target "android" which is not built by this project.

您需要确保首先列出您的图书馆:

target_link_libraries(
    my_native_code
    android)

关于android - 无法为不是由该项目构建的目标指定链接库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58819864/

相关文章:

java - libgdx,如何使我的图像可触摸

c++ - 等于运算符 : pointer to a member function

c++ - 有没有实现的说话人识别算法

java - 错误 : Unable to run the app with Firebase jar included

node.js - Firebase 云功能与批量更新不一致

android - 使 EditText 提示全部大写

android - 添加 react-native-firebase crashlytics 后,Android 应用程序在第二个构建中崩溃,MainApplication 出现 classNotFound 异常

java - 文件保存到公共(public)存储目录的问题

c++ - Opencv 2 Mat- 运行时错误

android - 程序类型已经存在 : android. support.v4.os.ResultReceiver$MyResultReceiver on Ionic