CMake add_subdirectory заданный источник, который не является существующим каталогом - PullRequest
1 голос
/ 11 ноября 2019

Я следую этому руководству, чтобы реализовать firebase в моем проекте Android с использованием C ++. Я выполнил все шаги, как показано в руководстве, но когда я запускаю свой проект, я получаю следующее сообщение об ошибке:

 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
}

Ответы [ 2 ]

1 голос
/ 12 ноября 2019

Ошибка жалуется, что каталог olympic/firebase_cpp_sdk не существует. Из документации для add_subdirectory() первый аргумент этой команды может быть относительным или абсолютным путем:

Если это относительный путь, он будет оцениваться относительнотекущий каталог (типичное использование), но это также может быть абсолютный путь.

Поскольку вы указали относительный путь, CMake будет искать olympic/firebase_cpp_sdk относительно текущего обрабатываемого файла CMakeLists.txt ;этот путь не существует в вашей системе. Чтобы убедиться, что CMake может найти каталог firebase_cpp_sdk, попробуйте вместо этого указать абсолютный путь, как предлагается в учебном руководстве на этом шаге:

Укажите расположение разархивированного SDK в файле gradle.properties вашего проекта:

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

Поэтому попробуйте полный путь:

systemProp.firebase_cpp_sdk.dir=/your/full/path/to/SDK
0 голосов
/ 12 ноября 2019

Вы должны указать путь к «firebase sdk» раньше:

# Add Firebase libraries to the target using the function from the SDK.
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)

, а затем установить этот путь для переменной cmake «FIREBASE_CPP_SDK_DIR»:

set(FIREBASE_CPP_SDK_DIR "${CMAKE_CURRENT_LIST_DIR}/<some relative path inside of your project>")

где CMAKE_CURRENT_LIST_DIR - путь, по которому находится текущий CMakeLists.txt.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...