gpt4 book ai didi

android - CMake add_subdirectory 给定的源不是现有目录

转载 作者:行者123 更新时间:2023-11-29 22:42:52 29 4
gpt4 key购买 nike

我正在关注 this教程,以便使用 C++ 在我的 android 项目中实现 firebase。我已按照教程所示的所有步骤进行操作,但是当我运行我的项目时,我收到此错误消息:

 CMake Error at CMakeLists.txt:46 (add_subdirectory):
add_subdirectory given source "olympic/firebase_cpp_sdk" which is not an
existing directory.

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}")

Build.gradle

apply plugin: 'com.android.library'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"


defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.deltadna.android:deltadna-sdk:4.11.3.1'
implementation 'com.helpshift:android-helpshift-aar:7.+'
implementation "com.mixpanel.android:mixpanel-android:5.+"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

apply plugin: 'com.google.gms.google-services'

android.defaultConfig.externalNativeBuild.cmake {
arguments "-DFIREBASE_CPP_SDK_DIR=$gradle.firebase_cpp_sdk_dir"
}

apply from: "firebase_cpp_sdk/Android/firebase_dependencies.gradle"
firebaseCpp.dependencies {
analytics
}

最佳答案

错误提示目录olympic/firebase_cpp_sdk 不存在。来自 add_subdirectory() 的文档,此命令的第一个参数可以是相对路径或绝对路径:

If it is a relative path it will be evaluated with respect to the current directory (the typical usage), but it may also be an absolute path.

由于您提供了相对路径,CMake 将查找olympic/firebase_cpp_sdk 相对于当前正在处理的 CMakeLists.txt 文件;您的系统上不存在此路径。为确保 CMake 可以找到 firebase_cpp_sdk 目录,请尝试指定一个绝对 路径,如本步骤教程中所建议:

  1. Specify the location of the unzipped SDK in your project's gradle.properties file:

     systemProp.firebase_cpp_sdk.dir=full-path-to-SDK

所以尝试完整路径:

systemProp.firebase_cpp_sdk.dir=/your/full/path/to/SDK

关于android - CMake add_subdirectory 给定的源不是现有目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58808530/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com