How to import the Firebase SDK into a Cocos2d-x Android project.

503 views
Skip to first unread message

coco

unread,
Mar 4, 2019, 12:26:22 AM3/4/19
to Firebase Google Group
I am using the official website.

I have problems with the item called "Set up Android" 
The reason is that this site corresponds to ndk-build. But I am using cmake.
I examined it. And I noticed. But I do not understand how to write it so I ask you a question like this.
I think that it is necessary to rewrite contents of Android.mk to CmakeLists.txt with Cocos2dx project.
But I examined but I did not know how to write it in CmakeLists.txt. Please tell me the correct code.


Android.mk

LOCAL_PATH := $(call my-dir)

 

# The path to the Firebase C++ SDK, in the project's root directory.

FIREBASE_CPP_SDK_DIR := ../../../firebase_cpp_sdk

 

APP_ABI := armeabi-v7a x86

STL := $(firstword $(subst _, ,$(APP_STL)))

FIREBASE_LIBRARY_PATH := $(FIREBASE_CPP_SDK_DIR)/libs/android/$(TARGET_ARCH_ABI)/$(STL)

 

include $(CLEAR_VARS)

LOCAL_MODULE := firebase_app

LOCAL_SRC_FILES := $(FIREBASE_LIBRARY_PATH)/libapp.a

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(FIREBASE_CPP_SDK_DIR)/include

include $(PREBUILT_STATIC_LIBRARY)

 

include $(CLEAR_VARS)

LOCAL_MODULE := firebase_feature

LOCAL_SRC_FILES := $(FIREBASE_LIBRARY_PATH)/libadmob.a

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(FIREBASE_CPP_SDK_DIR)/include

include $(PREBUILT_STATIC_LIBRARY)

 

include $(CLEAR_VARS)

 

$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d)

$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/external)

$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos)

$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos/audio/include)

 

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

 

LOCAL_SRC_FILES := hellocpp/main.cpp \

                   ../../../Classes/AppDelegate.cpp \

                   ../../../Classes/HelloWorldScene.cpp

 

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes

 

# _COCOS_HEADER_ANDROID_BEGIN

# _COCOS_HEADER_ANDROID_END

 

LOCAL_STATIC_LIBRARIES := cocos2dx_static

LOCAL_STATIC_LIBRARIES += firebase_app

LOCAL_STATIC_LIBRARIES += firebase_feature

 

# _COCOS_LIB_ANDROID_BEGIN

# _COCOS_LIB_ANDROID_END

 

include $(BUILD_SHARED_LIBRARY)

 

$(call import-module,.)

 

# _COCOS_LIB_IMPORT_ANDROID_BEGIN

# COCOS_LIB_IMPORT_ANDROID_NED



CmakeLists.txt

cmake_minimum_required(VERSION 3.6)


set(APP_NAME FirebaseSample)


project(${APP_NAME})


set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cocos2d)

set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)


include(CocosBuildSet)

add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)


# record sources, headers, resources...

set(GAME_SOURCE)

set(GAME_HEADER)


set(GAME_RES_FOLDER

    "${CMAKE_CURRENT_SOURCE_DIR}/Resources"

    )

if(APPLE OR WINDOWS)

    cocos_mark_multi_resources(common_res_files RES_TO "Resources" FOLDERS ${GAME_RES_FOLDER})

endif()


# add cross-platforms source files and header files 

list(APPEND GAME_SOURCE

     Classes/AppDelegate.cpp

     Classes/HelloWorldScene.cpp

     )

list(APPEND GAME_HEADER

     Classes/AppDelegate.h

     Classes/HelloWorldScene.h

     )


if(ANDROID)

    # change APP_NAME to the share library name for Android, it's value depend on AndroidManifest.xml

    set(APP_NAME MyGame)

    list(APPEND GAME_SOURCE

         proj.android/app/jni/hellocpp/main.cpp

         )

elseif(LINUX)

    list(APPEND GAME_SOURCE

         proj.linux/main.cpp

         )

elseif(WINDOWS)

    list(APPEND GAME_HEADER

         proj.win32/main.h

         proj.win32/resource.h

         )

    list(APPEND GAME_SOURCE

         proj.win32/main.cpp

         proj.win32/game.rc

         ${common_res_files}

         )

elseif(APPLE)

    if(IOS)

        list(APPEND GAME_HEADER

             proj.ios_mac/ios/AppController.h

             proj.ios_mac/ios/RootViewController.h

             )

        set(APP_UI_RES

            proj.ios_mac/ios/LaunchScreen.storyboard

            proj.ios_mac/ios/LaunchScreenBackground.png

            proj.ios_mac/ios/Images.xcassets

            )

        list(APPEND GAME_SOURCE

             proj.ios_mac/ios/main.m

             proj.ios_mac/ios/AppController.mm

             proj.ios_mac/ios/RootViewController.mm

             proj.ios_mac/ios/Prefix.pch

             ${APP_UI_RES}

             )

    elseif(MACOSX)

        set(APP_UI_RES

            proj.ios_mac/mac/Icon.icns

            proj.ios_mac/mac/Info.plist

            )

        list(APPEND GAME_SOURCE

             proj.ios_mac/mac/main.cpp

             proj.ios_mac/mac/Prefix.pch

             ${APP_UI_RES}

             )

    endif()

    list(APPEND GAME_SOURCE ${common_res_files})

endif()


# mark app complie info and libs info

set(all_code_files

    ${GAME_HEADER}

    ${GAME_SOURCE}

    )

if(NOT ANDROID)

    add_executable(${APP_NAME} ${all_code_files})

else()

    add_library(${APP_NAME} SHARED ${all_code_files})

    add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/platform/android ${ENGINE_BINARY_PATH}/cocos/platform)

    target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive)

endif()


target_link_libraries(${APP_NAME} cocos2d)

target_include_directories(${APP_NAME}

        PRIVATE Classes

        PRIVATE ${COCOS2DX_ROOT_PATH}/cocos/audio/include/

)


# mark app resources

setup_cocos_app_config(${APP_NAME})

if(APPLE)

    set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}")

    if(MACOSX)

        set_target_properties(${APP_NAME} PROPERTIES

                              MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/mac/Info.plist"

                              )

    elseif(IOS)

        cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")

        set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")

    endif()

elseif(WINDOWS)

    cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_RES_DIR}/..)

endif()


if(LINUX OR WINDOWS)

    cocos_copy_res(COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})

endif()

Alex Ames

unread,
Mar 6, 2019, 5:46:31 PM3/6/19
to Firebase Google Group
The first thing that I notice is that you have a few references to firebase_feature. You should replace "feature" with the actual library name you're trying to include. 

You can also use our quickstart apps as a reference. They use CMake to build, so you can compare their CMakeLists.txt file against your own to compare and contrast.

Here is one example:

Reply all
Reply to author
Forward
0 new messages