我试图将firebase c ++ sdk添加到我的cocos2d-x 3.14游戏中。到目前为止,我已经在firebase_cpp_sdk目录中创建了Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := firebase-prebuilt
LOCAL_SRC_FILES := libs/android/$(TARGET_ARCH_ABI)/c++/libapp.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := firebase-analytics
LOCAL_SRC_FILES := libs/android/$(TARGET_ARCH_ABI)/c++/libanalytics.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
然后在Android.mk的项目中,我添加了:
LOCAL_C_INCLUDES += /Users/piotr/Documents/pierdoly/firebase_cpp_sdk/include
LOCAL_STATIC_LIBRARIES += firebase-prebuilt firebase-analytics
$(call import-add-path, /Users/piotr/Documents/pierdoly/firebase_cpp_sdk)
我可以同步gradle和构建项目。 我也可以
#include <firebase/app.h>
在AppDelegate.cpp(或h)中,它工作正常。即使Android工作室也可以看到所有的firebase标题,我可以检查它们。
现在,在applicationDidFinishLaunching中我添加了这个:
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
::firebase::App* app = ::firebase::App::Create(::firebase::AppOptions());
#else
::firebase::App* firebaseApp = ::firebase::App::Create(::firebase::AppOptions(), cocos2d::JniHelper::getEnv(), cocos2d::JniHelper::getActivity());
#endif
还有来自AppActivity.java的JNICALL的替代版本(传递正确的活动,因为有人说上面的解决方案不起作用):
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
JNIEXPORT void JNICALL Java_org_cocos2dx_cpp_AppActivity_initFirebase(JNIEnv* env, jobject thiz)
{
::firebase::App* app = ::firebase::App::Create(::firebase::AppOptions(), env, thiz);
}
#endif
然而我的问题是:它甚至无法编译。那里有链接器错误:
Error:(141) undefined reference to 'firebase::App::Create(firebase::AppOptions const&, _JNIEnv*, _jobject*)'
我可以清楚地&#34;去&#34;在Android Studio中使用此功能,我已经重新检查了两次我给出的参数。他们很好。然而,链接器对我大喊大叫。
如何修复链接器?我在这里缺少什么?
答案 0 :(得分:0)
I had the same problem but found the answer:
It's about the order of the libraries being linked. You just have to rearrange it like this:
LOCAL_STATIC_LIBRARIES += firebase-analytics firebase-prebuilt
And it should work.
Say thanks to the guys in this github issue
答案 1 :(得分:0)
Cocos使用不同的utils进行本机库构建,它可以是 cmake 或 ndk util,因此请检查您的frameworks / runtime-src / proj.android / gradle。属性选项 PROP_BUILD_TYPE ,然后将其是否需要从 cmake 更改为 ndk-build 然后在 frameworks / runtime-src / proj.android / app / build.gradle 上查看 build.gradle ,它必须正确使用 ndk-build