qt 6.3 firebase cpp sdk integration for android(cmake)

Viewed 26

so I've been trying to integrate the newest cpp sdk(9.5) into my Qt6 cmake android application. dependencies used

openjdk 11
ndk22.1.7171670
gradle 7.4(default from the qt android package template)

I've put the whole sdk dir inside my project.

here is the top level CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(kushok-client VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(ANDROID)

    include(${ANDROID_SDK_ROOT}/android_openssl/CMakeLists.txt)

endif()

find_package(Qt6  COMPONENTS Core REQUIRED)
find_package(Qt6  COMPONENTS Quick REQUIRED)
find_package(Qt6  COMPONENTS Multimedia REQUIRED)
find_package(Qt6  COMPONENTS Gui REQUIRED)
find_package(Qt6  COMPONENTS Network REQUIRED)
find_package(Qt6  COMPONENTS Charts REQUIRED)
find_package(Qt6  COMPONENTS Svg REQUIRED)
find_package(Qt6  COMPONENTS Core5Compat REQUIRED)
find_package(Qt6  COMPONENTS WebSockets REQUIRED)
find_package(Qt6  COMPONENTS LinguistTools REQUIRED)

set(FIREBASE_CPP_SDK_DIR "${CMAKE_CURRENT_LIST_DIR}/libs/firebase_cpp_sdk")
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
add_subdirectory(src/app)

and inside src/app/CMakeLists.txt

    if(ANDROID)
    set(ANDROID_PACKAGE_SOURCE_DIR android
        CACHE INTERNAL "")
endif()
qt_add_executable(appkushok-client
    cpp/core.h cpp/core.cpp
    assets/images/images.qrc
    assets/images/icons/icons.qrc
    assets/fonts/fonts.qrc
    cpp/main.cpp
)

target_include_directories(appkushok-client PUBLIC ${INCLUDE_DIR})
    qt_add_qml_module(appkushok-client
        URI KushokClient
        VERSION 1.0
        QML_FILES
            qml/main.qml
            js/utils.js
    )


set_target_properties(appkushok-client PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

if(ANDROID)
set_target_properties(appkushok-client PROPERTIES QT_ANDROID_EXTRA_LIBS "${ANDROID_EXTRA_LIBS}")
endif()

target_link_libraries(appkushok-client PRIVATE Qt6::Quick
Qt6::Core
Qt6::Multimedia
Qt6::Gui
Qt6::Network
Qt6::Charts
Qt6::Svg
Qt6::Core5Compat
Qt6::WebSockets
)

set(firebase_libs
firebase_messaging
firebase_auth
firebase_app
)
target_link_libraries(appkushok-client PRIVATE "${firebase_libs}")
target_compile_definitions(appkushok-client
    PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)

then I followed the instructions here

here is my build.gradle

    buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.2'
            // Add the following lines:
    classpath 'com.google.gms:google-services:4.3.14'  // Google Services plugin
    implementation 'com.google.android.gms:18.1.0'

    }
}

repositories {
    google()
    mavenCentral()
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'  // Google Services plugin

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

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

# Add the dependencies for the Firebase products you want to use in your app
# For example, to use Firebase Authentication and Firebase Realtime Database
apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle"
firebaseCpp.dependencies {
auth
database
}


android {
    /*******************************************************
    * The following variables:
    * - androidBuildToolsVersion,
    * - androidCompileSdkVersion
    * - qtAndroidDir - holds the path to qt android files
    *                   needed to build any Qt application
    *                   on Android.
    *
    * are defined in gradle.properties file. This file is
    * updated by QtCreator and androiddeployqt tools.
    * Changing them manually might break the compilation!
    *******************************************************/

    compileSdkVersion androidCompileSdkVersion.toInteger()
    buildToolsVersion androidBuildToolsVersion
    ndkVersion androidNdkVersion

    // Extract native libraries from the APK
    packagingOptions.jniLibs.useLegacyPackaging true

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = [qtAndroidDir + '/src', 'src', 'java']
            aidl.srcDirs = [qtAndroidDir + '/src', 'src', 'aidl']
            res.srcDirs = [qtAndroidDir + '/res', 'res']
            resources.srcDirs = ['resources']
            renderscript.srcDirs = ['src']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
    }
    }

    tasks.withType(JavaCompile) {
        options.incremental = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {
        abortOnError false
    }

    // Do not compress Qt binary resources file
    aaptOptions {
        noCompress 'rcc'
    }

    defaultConfig {
        resConfig "en"
        minSdkVersion qtMinSdkVersion
        targetSdkVersion qtTargetSdkVersion
        ndk.abiFilters = qtTargetAbiList.split(",")
    }
}

and settings.gradle

def firebase_cpp_sdk_dir = System.getProperty('firebase_cpp_sdk.dir')

gradle.ext.firebase_cpp_sdk_dir = "$firebase_cpp_sdk_dir"
includeBuild "$firebase_cpp_sdk_dir"

I hardcoded the firebase cpp sdk path inside gradle.properties just to make sure it works

org.gradle.jvmargs=-Xmx2500m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
systemProp.firebase_cpp_sdk.dir=/home/sadeq/projects/kushok/mobile/kiosk-client-app-base/libs/firebase_cpp_sdk

I added the google-services.json inside my android package dir and my manifest contains this service

    <service android:name=".com.google.firebase.messaging.MessageForwardingService">
        <meta-data android:name="android.app.background_running" android:value="true"/>
        <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
    </service>

the projects compiles fine but crashes at runtime with this message

E firebase: Java class com/google/firebase/FirebaseApp not found.  Please verify the AAR which contains the com/google/firebase/FirebaseApp class is included in your app.
E firebase: clazz
F firebase: Java class com/google/firebase/FirebaseApp not found.  Please verify the AAR which contains the com/google/firebase/FirebaseApp class is included in your app.
F libc    : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 26087 (qtMainLoopThrea), pid 26062 (ppkushok_client)

it seems that the firebase java libraries were not imported, I've tried putting the cpp sdk inside ANDROID_PACKAGE_SOURCE_DIR/libs but it did not make a difference.

0 Answers
Related