Integration guide?

Hi, I'm trying to integrate photon realtime sdk into my cocos2d-x game, however I cannot find integration guide. There's only this article: https://doc.photonengine.com/en-us/realtime/current/getting-started/realtime-intro which doesn't help much. I've downloaded Android / iOS sdks, but there isn't how-to-add-to-project guide anywhere. I've started from iOS, as it should be simpler - I've added all the libraries like this:

https://imgur.com/ENZJ3CU

but it won't compile. It's probably just a path error, but it's SO STRANGE to me that there isn't any guide how to do it right. Just a zip file with bunch of directories and that's it. Can someone guide me?

Comments

  • KaiserludiKaiserludi admin
    edited July 2019
    Hi @piotrros.

    Please take a look at the Xcode project and target settings of one of the demo projects in the ./Demos folder inside the iOS client SDK for an example on how to add Photon to your Xcode project.

    The important settings are:
    - add the relative path to the parent directory of Common-cpp/inc, Photon-cpp/inc and LoadBalancing-cpp/inc to to "Header Search Paths" in category "Search Paths".
    - add the relative paths to Common-cpp/lib, Photon-cpp/lib and LoadBalancing-cpp/lib to "Library Search Paths" in category "Search Paths"
    - add the following lines: to "Other Linker Flags" in category "Linking":
    
    	-lstdc++
    	-force_load
    	../../../Common-cpp/lib/libCommon-cpp_$(CONFIGURATION)_$(PLATFORM_NAME).a
    	-lCommon-cpp_$(CONFIGURATION)_$(PLATFORM_NAME)
    	-lPhoton-cpp_$(CONFIGURATION)_$(PLATFORM_NAME)
    	-lLoadBalancing-cpp_$(CONFIGURATION)_$(PLATFORM_NAME)
    
    - Add the following #include directive to your source-code:
    #include "LoadBalancing-cpp/inc/Client.h"

    If you open the project.pbxproj file of your Xcode project in a text-editor, then it should have at least these entries (there might be more entries, which are not related to Photon):
    
    				HEADER_SEARCH_PATHS = (
    					../../..,
    				);
    				LIBRARY_SEARCH_PATHS = (
    					"../../../Common-cpp/lib",
    					"../../../Photon-cpp/lib",
    					"../../../LoadBalancing-cpp/lib",
    				);
    				OTHER_LDFLAGS = (
    					"-lstdc++",
    					"-force_load",
    					"../../../Common-cpp/lib/libCommon-cpp_$(CONFIGURATION)_$(PLATFORM_NAME).a",
    					"-lCommon-cpp_$(CONFIGURATION)_$(PLATFORM_NAME)",
    					"-lPhoton-cpp_$(CONFIGURATION)_$(PLATFORM_NAME)",
    					"-lLoadBalancing-cpp_$(CONFIGURATION)_$(PLATFORM_NAME)",
    				);
    
  • Great, thanks for the help! I've got it working now. I think you should really include this in docs, it is not obvious (especially compiler flags).
  • Okay, so iOS is working fine, but I struggle with android integration. As I use cocos2d-x it's not that straightforward to just copy stuff from demo project.

    I've carefully gone through every line in Android.mk file in demo project and tried to incorporate into mine Android.mk file.

    However, as you may already suspect, I've got an error:
    D:/android-ndk/build//../sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:74: error: undefined reference to 'std::ios_base::Init::Init()'
    jni/../src/AuthenticationValues.cpp:175: error: undefined reference to 'std::ios_base::Init::~Init()'
    D:/android-ndk/build//../sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:74: error: undefined reference to 'std::ios_base::Init::Init()'
    jni/../src/Client.cpp:2449: error: undefined reference to 'std::ios_base::Init::~Init()'
    D:/android-ndk/build//../sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:74: error: undefined reference to 'std::ios_base::Init::Init()'
    jni/../src/FriendInfo.cpp:61: error: undefined reference to 'std::ios_base::Init::~Init()'
    D:/android-ndk/build//../sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:74: error: undefined reference to 'std::ios_base::Init::Init()'
    jni/../src/Internal/AuthenticationValuesSecretSetter.cpp:24: error: undefined reference to 'std::ios_base::Init::~Init()'
    D:/android-ndk/build//../sources/cxx-stl/gnu-libstdc++/4.9/include/mutex:139: error: undefined reference to 'std::__throw_system_error(int)'
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    This error is very cryptic, but I suspect it may be related to APP_STL in Application.mk file, as in cocos2d-x I use APP_STL := c++_static and in demo project it is APP_STL := gnustl_static

    I don't think changing it is a good idea, but I've tried anyway. And here's the error:
    In file included from /Users/piotr/Documents/projekty/gry/MultiplayerCrazyChicken/proj.android-studio/app/jni/../../../Classes/GameScene.cpp:1:
    In file included from /Users/piotr/Documents/projekty/gry/MultiplayerCrazyChicken/proj.android-studio/app/jni/../../../Classes/GameScene.h:12:
    In file included from /Users/piotr/Documents/pierdoly/cocos2d-x-3.17_git/cocos/cocos2d.h:42:
    In file included from /Users/piotr/Documents/pierdoly/cocos2d-x-3.17_git/cocos/base/CCAsyncTaskPool.h:38:
    In file included from /Users/piotr/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/future:43:
    /Users/piotr/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/atomic:175:7: error: exception specification of explicitly defaulted default constructor does not match the calculated one
          atomic() noexcept = default;
          ^
    /Users/piotr/Documents/projekty/gry/MultiplayerCrazyChicken/proj.android-studio/app/jni/../../Common-cpp/inc/Helpers/Spinlock.h:28:29:/Users/piotr/Documents/projekty/gry/MultiplayerCrazyChicken/proj.android-studio/app/jni/../../Common-cpp/inc/Helpers/Spinlock.h:28:29: note: in instantiation of template class 'std::atomic' requested here
    /Users/piotr/Documents/projekty/gry/MultiplayerCrazyChicken/proj.android-studio/app/jni/../../Common-cpp/inc/Helpers/Spinlock.h:28:29:                                std::atomic mLockOwner;
                                                             ^note:  note
    : in instantiation of template class 'std::atomic' requested here
                                    std::atomic mLockOwner;
                                                            ^
    in instantiation of template class 'std::atomic' requested here
                                    std::atomic mLockOwner;
                                                            ^
    How can I fix this? Can you guide me again? Am I forced to use gnustl_static instead of c++_static?

    What version of NDK does Photon Engine require? (I think this may be problematic as well).

    Here's my Application.mk file:
    #APP_STL := c++_static
    APP_STL := gnustl_static
    
    APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char -Wno-extern-c-compat
    APP_LDFLAGS := -latomic
    
    APP_ABI := armeabi-v7a
    APP_SHORT_COMMANDS := true
    
    
    ifeq ($(NDK_DEBUG),1)
      APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
      APP_OPTIM := debug
    else
      APP_CPPFLAGS += -DNDEBUG
      APP_OPTIM := release
    endif
    And here's my Android.mk file:
    LOCAL_PATH := $(call my-dir)
    PHOTON_SDK_ROOT := $(LOCAL_PATH)/../..
    
    include $(CLEAR_VARS)
    COCOS_ROOT := /Users/piotr/Documents/pierdoly/cocos2d-x-3.17_git
    
    
    $(call import-add-path,$(COCOS_ROOT))
    
    LOCAL_MODULE := MyGame_shared
    
    LOCAL_MODULE_FILENAME := libMyGame
    
    FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../gamesparks/src/*.cpp)
    
    LOCAL_SRC_FILES := $(LOCAL_PATH)/hellocpp/main.cpp \
                       $(FILE_LIST:$(LOCAL_PATH)/%=%) \
                       $(LOCAL_PATH)/../../../Classes/AppDelegate.cpp \
                       $(LOCAL_PATH)/../../../Classes/GameScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/LoadingScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/InAppScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/ExtrasScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/MenuScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/AppItem.cpp \
                       $(LOCAL_PATH)/../../../Classes/EditKidScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/KidsScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/OurAppsScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/KidsPlotScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/KidsPercentsScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/KidsActivityScene.cpp \
                       $(LOCAL_PATH)/../../../Classes/NativeHelperAndroid.cpp \
                       $(LOCAL_PATH)/../../../Classes/RUtils.cpp \
                       $(LOCAL_PATH)/../../../Classes/NetworkLogic.cpp \
                       $(LOCAL_PATH)/../../../Classes/Console.cpp \
                       $(LOCAL_PATH)/../../../Classes/OutputListener.h \
                       $(LOCAL_PATH)/../../../Classes/Definitions.h
    
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../gamesparks/include \
                        $(PHOTON_SDK_ROOT) \
                        $(LOCAL_PATH)/../../../Classes
    
    LOCAL_CFLAGS := -Werror-implicit-function-declaration -Wall -DEG_DEBUGGER -D__STDINT_LIMITS -D_EG_ANDROID_PLATFORM
    LOCAL_STATIC_LIBRARIES := loadbalancing-cpp-static-prebuilt photon-cpp-static-prebuilt common-cpp-static-prebuilt
    
    LOCAL_LDLIBS := -llog -latomic
    
    # _COCOS_HEADER_ANDROID_BEGIN
    # _COCOS_HEADER_ANDROID_END
    
    LOCAL_WHOLE_STATIC_LIBRARIES := cc_static
    
    # _COCOS_LIB_ANDROID_BEGIN
    # _COCOS_LIB_ANDROID_END
    
    include $(BUILD_SHARED_LIBRARY)
    
    $(call import-module, prebuilt/android)
    
    # _COCOS_LIB_IMPORT_ANDROID_BEGIN
    # _COCOS_LIB_IMPORT_ANDROID_END
    
    $(call import-add-path, $(PHOTON_SDK_ROOT)/LoadBalancing-cpp/lib)
    $(call import-module,loadbalancing-cpp-prebuilt)
    Note: game sparks is previous network engine used, I haven't get rid of it completely just yet, but I shouldn't make an issues, because I'm not calling it in code anyway (and on iOS it is fine).
    Note2: I'm pretty sure PHOTO_SDK_ROOT is fine.
  • Hi @piotrros.

    Please use APP_STL := c++_static and additionally please also link against the libc++ variants of the libs by following my instructions at https://forum.photonengine.com/discussion/comment/42718/#Comment_42718.

    Background info:
    The app and all libs that it links against, must have been built against the same version of the standard library as the clang and the GCC standard library are not binary compatible to each other.
    The Photon SDK comes with libs which have been built against libstdc++ (the ones without the '_libc++' postfix in their filenames) and also with libs which have been built against libc++ (the ones, which have the '_libc++' postfix in their filenames).

    Which ones you need to link against depends on the question, which standard library your app uses, which in turn depends on the version of the Android NDK that you use and on which other 3rd party libraries you use.
    i.e. NDK version r18 and up only supports clang, while very old versions (r8 or so and downwards - not sure out of my head which version exactly introduced clang support) only supported GCC, Unreal Engine requires the app to use GCC and cocos2d-x has until relatively recently also required GCC, before it switched over to clang.
  • Yay, now it works. Adding _libc++ suffix helped. Thanks!
Sign In or Register to comment.