Android Studio Support?


This is for the Realtime Android c ++ client. Do you provide support in how to integrate the photon Realtime Android client into a Android Studio project? Thanks,


  • Hi @GreenRollingHills.

    The Photon Client SDK for Android NDK ships with multiple demo projects and those demos come with make-files that link against the Photon libraries. They also contain some Java code that calls the C++ code through JNI.

    Please see for general information about how to link a static NDK library in an Android Studio project.
  • Hello,

    Thanks for your response. I checked the link. It suggests that I have the make-file, source files and all of the static libraries in the src/main/jni folder. I was expecting that I had to modify the make-files in the downloaded Photon SDK then use Android Studio's "Link C++ Project with Gradle" process to link to one of these modified make-files.

    Am I really to copy all the files from Photon's SDK into my Android Studio project similar to the link you shared?

  • Hi @GreenRollingHills.

    i think that following the guide from you link should also work.

    Why do you think you need to modify anything the make-files?

    For your information:
    We don't use Android Studio ourselves, so I don't have first-hands experience with it.
  • edited May 2018

    Note: I have limited experience with Android Studio and almost no experience with make-files.

    I think I need to modify the make-file because I couldn't get it to work as is.

    I created a new Android Studio with c ++ support and linked to /Users/myName/Downloads/Photon-AndroidNDK-Sdk_v4-1-9-0-2/Demos/demo_loadBalancing/android/jni/ in the photon SDK downloaded folder. And I didn't move any libs nor source files to my Android Studio project. When I tried to build the Android Studio project I get the following error:

    Build command failed.
    Error while executing process /Users/myName/Library/Android/sdk/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/myName/Downloads/Photon-AndroidNDK-Sdk_v4-1-9-0-2/Demos/demo_loadBalancing/android/jni/ NDK_APPLICATION_MK=/Users/myName/Downloads/Photon-AndroidNDK-Sdk_v4-1-9-0-2/Demos/demo_loadBalancing/android/jni/ APP_ABI=x86_64 NDK_ALL_ABIS=x86_64 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/Users/myName/Documents/developmentPractice/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/Users/myName/Documents/developmentPractice/app/build/intermediates/ndkBuild/debug/lib /Users/myName/Documents/developmentPractice/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/}
    [x86_64] Compile++ : demoLoadBalancing <= NetworkLogic.cpp
    /Users/myName/Downloads/Photon-AndroidNDK-Sdk_v4-1-9-0-2/Demos/demo_loadBalancing/android/jni/../../src/NetworkLogic.cpp:1:10: fatal error: 'NetworkLogic.h' file not found
    #include "NetworkLogic.h"
    1 error generated.
    make: *** [/Users/myName/Documents/developmentPractice/app/build/intermediates/ndkBuild/debug/obj/local/x86_64/objs-debug/demoLoadBalancing/__/__/src/NetworkLogic.o] Error 1

    There is only one header file in the Android Studio project. It is the AndroidNetworkLogic.h file.

  • KaiserludiKaiserludi admin
    edited May 2018
    Hi @GreenRollingHills.

    That looks like Android Studio can't find NetworkLogic.h, because it isn't aware that it should look for header files at any other paths than the one where the makefile is located.

    See for how to add additional include paths and add the path to NetworkLogic.h.
  • Hello,

    Thanks for the reply. I got it to work.

    I do have a follow up question. Is it recommended to subclass NetworkLogic or AndroidNetworkLogic? If so, how for example am I to get access to “mLoadBalancingClient”?

  • Hi @GreenRollingHills.

    NetworkLogic and AndroidNetworkLogic are both part of demo_loadBalancing, which is a demo project and not a library.
    So these classes are basically example code for how to use the libraries.

    Hence the recommended approach is to use them as an example for how you would write your own network logic.
    So no, these classes are not written with the intention to be subclassed.

    Many developers start by copy-and-pasting the the NetworkLogic class into their games code base as a starting point for their games networking code and then modify it to match their games specific requirements.
    When doing so instead of writing you own network logic from scratch, then feel free to modify that copy however it makes sense to you, just as if you would be the original author of that class.
  • Ok. Thanks for the info. You have answered all my questions.
Sign In or Register to comment.