Android Studio Support?

Hello,

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,

Comments

  • 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 http://blog.marcingil.com/android-ndk-link-static-library-to-your-jni-library/ 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?

    Thanks,
  • 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.
  • GreenRollingHills
    edited May 2018
    Hello,

    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/Android.mk 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/Android.mk NDK_APPLICATION_MK=/Users/myName/Downloads/Photon-AndroidNDK-Sdk_v4-1-9-0-2/Demos/demo_loadBalancing/android/jni/Application.mk 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/libdemoLoadBalancing.so}
    [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.



  • Kaiserludi
    Kaiserludi 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 https://stackoverflow.com/questions/33658745/how-does-one-set-a-c-c-include-path-with-gradle-experimental-plugin 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”?

    Thanks,
  • 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.
  • Kaiserludi wrote: »
    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 http://blog.marcingil.com/android-ndk-link-static-library-to-your-jni-library/ for general information about how to link a static NDK library in an Android Studio project.

  • baymax
    baymax
    edited July 2020
    provided link is not available.
    http://blog.marcingil.com/android-ndk-link-static-library-to-your-jni-library/
    I am work on android studio to integrate photon sdk. unfortunately, i didn't find fit code.
  • Hi @baymax.

    You can simply google for
    how to link a static NDK library in an Android Studio project
    to find alternative guides.
  • Daguo
    Daguo
    edited September 2020
    Hi @baymax

    I recreate the "demo_loadBalancing" project by android studio. you can try this steps.
  • Hi @Daguo.

    Thank you for writing that guide.

    For everyone who can't read Chinese, here is a goggle translation of the above link:
    https://translate.google.com/translate?hl=&amp;sl=auto&amp;tl=en&amp;u=https://blog.csdn.net/ldghd/article/details/108409518

    I noticed that you have modified the nameserver address inside Client.cpp to point to your own self-hosted server.

    You don't need to do that, but can simply pass the address of your Photon server to Client::connect().

    Furthermore your comment on that change indicates that you did so because ns.exitgames.com is not reachable from within China.
    As explained at https://doc.photonengine.com/en-US/realtime/current/connection-and-authentication/regions/#using_the_chinese_mainland_region we provide a Chinese Photon Name Server with the address "ns.photonengine.cn".
    Of course you can also just host your own Photon server in China if you prefer so, but it is not the only option.
  • Hi @Kaiserludi admin

    Thank you for your reply.I have updated the guide.