简体   繁体   English

Firebase 未解析的外部符号

[英]Firebase unresolved external symbol

When I run my app in cocos2d, it prints the error:当我在 cocos2d 中运行我的应用程序时,它会打印错误:

2> Creating library C:\\Users\\Will\\Documents\\Projects\\Home\\proj.win32\\Debug.win32\\Home.lib and object C:\\Users\\Will\\Documents\\Projects\\Home\\proj.win32\\Debug.win32\\Home.exp 2>AppDelegate.obj : error LNK2001: unresolved external symbol "void * firebase::g_admob_initializer" (?g_admob_initializer@firebase@@3PAXA) 2>C:\\Users\\Will\\Documents\\Projects\\Home\\proj.win32\\Debug.win32\\Home.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 1 succeeded, 1 failed, 4 up-to-date, 0 skipped ==========

I have no idea why.我不知道为什么。 My app is literally the default cocos2d app, with the addition of the information in the firebase tutorial.我的应用程序实际上是默认的 cocos2d 应用程序,并在 firebase 教程中添加了信息。 All I did was include firebase\\admob.h and it causes the error.我所做的只是包含firebase\\admob.h并导致错误。 It doesn't cause the error when I include firebase\\app.h for some reason.当我出于某种原因包含firebase\\app.h时,它不会导致错误。

cocos2d verison: 3.15.1 cocos2d 版本:3.15.1

NDK: v15 NDK:v15

SDK: 26.0.0 SDK:26.0.0

It's saying unresolved external symbol, so I'm guessing that it has something to do with linking, but in my Android.mk, I link it.它说未解析的外部符号,所以我猜它与链接有关,但在我的 Android.mk 中,我链接了它。

app\\jni\\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_admob
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_admob

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

build.gradle

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "com.call.home"
        minSdkVersion 14
        targetSdkVersion PROP_TARGET_SDK_VERSION
        versionCode 1
        versionName "1.0"

        externalNativeBuild {
            ndkBuild {
                if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
                    // skip the NDK Build step if PROP_NDK_MODE is none
                    targets 'MyGame'
                    arguments 'NDK_TOOLCHAIN_VERSION=4.9'
                    arguments 'APP_PLATFORM=android-'+PROP_TARGET_SDK_VERSION

                    def module_paths = [project.file("../../cocos2d").absolutePath,
                                        project.file("../../cocos2d/cocos").absolutePath,
                                        project.file("../../cocos2d/external").absolutePath]
                    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                        // should use '/'
                        module_paths = module_paths.collect {it.replaceAll('\\\\', '/')}
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
                    }
                    else {
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
                    }

                    arguments '-j' + Runtime.runtime.availableProcessors()
                    abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String})
                }
            }
        }
    }

    sourceSets.main {
        java.srcDir "src"
        res.srcDir "res"
        manifest.srcFile "AndroidManifest.xml"
        assets.srcDir "../../Resources"
    }

    externalNativeBuild {
        ndkBuild {
            if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
                // skip the NDK Build step if PROP_NDK_MODE is none
                path "jni/Android.mk"
            }
        }
    }

    signingConfigs {

       release {
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                signingConfig signingConfigs.release
            }

            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=0'
                }
            }
        }

        debug {
            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=1'
                }
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':libcocos2dx')
    compile 'com.google.firebase:firebase-ads:11.4.0'
}

apply plugin: 'com.google.gms.google-services'

Just to note, this is only in Visual Studio.请注意,这仅在 Visual Studio 中。 Compiling it in command prompt or Android Studio doesn't create this problem.在命令提示符或 Android Studio 中编译它不会产生此问题。

Also noting, when I remove the line that says FIREBASE_APP_REGISTER_CALLBACKS_REFERENCE(admob) from the admob.h file, it works.另请注意,当我从 admob.h 文件中删除FIREBASE_APP_REGISTER_CALLBACKS_REFERENCE(admob)行时,它可以工作。 However, I'm worried that it'd screw something up down the line so I'll hold of on that solution.但是,我担心它会把事情搞砸,所以我会坚持那个解决方案。

This is the error that results when you haven't added the firebase libraries to your project.这是当您尚未将 firebase 库添加到项目时导致的错误。 You should verify by right-clicking on your project, then navigate to您应该通过右键单击您的项目来验证,然后导航到

Properties / Configuration Properties / Linker / Input / Additional Dependencies属性/配置属性/链接器/输入/附加依赖项

and make sure you have (-d prefix for debug): firebase_admob-d.lib and any other firebase_***-d.lib that it depends on.并确保您有(-d 前缀用于调试):firebase_admob-d.lib 和它所依赖的任何其他 firebase_***-d.lib。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM