【问题标题】:C++ Firebase linking error in android projectandroid项目中的C ++ Firebase链接错误
【发布时间】:2017-05-26 02:48:20
【问题描述】:

我正在尝试将 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 Studio 也可以看到所有 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*)'

我可以清楚地“进入”Android Studio 中的这个函数,并且我已经重新检查了两次我提供的参数。他们很好。然而链接器对我大喊大叫。

如何修复链接器?我在这里错过了什么?

【问题讨论】:

  • 这个问题你解决了吗?

标签: android c++ firebase android-ndk ndk-build


【解决方案1】:

我遇到了同样的问题,但找到了答案:

这与链接库的顺序有关。 你只需要像这样重新排列它:

LOCAL_STATIC_LIBRARIES += firebase-analytics firebase-prebuilt

它应该可以工作。

感谢github issue中的人

【讨论】:

    【解决方案2】:

    Cocos 使用不同的 utils 来构建原生库,可以是 cmakendk utils,因此请查看您的 frameworks/runtime-src/proj.android/gradle。属性选项 PROP_BUILD_TYPE 并根据需要从 cmake 更改为 ndk-build 然后在 frameworks/runtime-src/proj.android/app/build.gradle 上查看 build.gradle 它必须正确使用 ndk-build .

    【讨论】:

      猜你喜欢
      • 2021-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-01
      相关资源
      最近更新 更多