Setting up Android.mk with AndroidNDK

Options
victor
edited June 2015 in Native
Hi, I've been trying to get the Android.mk to recognise and include the Photon Android NDK Library files to no avail.

The Photon Doc as how to set up your application for Android NDK is quite vague, and the first line
"1. Add common-cpp-static-prebuilt and photon-cpp-static-prebuilt to "APP_CPPFLAGS" in your applications Android.mk file." is confusing, given that

"APP_CPPFLAGS" exists in Application.mk
and
"common-cpp-static-prebuilt" exists in Android.mk

I've been following http://codebygeorgeguy.wordpress.com/ posts on how to set up Photon on Android with Cocos2dx, which is further confusing, given how different it is from the Photon doc guide.

Hoping to find advice here, given how sparse help is elsewhere. Anyone managed to set up the Android.mk file successfully? Thanks.

Comments

  • Kaiserludi
    Options
    Hi victor.

    I have just had a look into the doc and the demo setups and identified this is an error in the doc:

    The "APP_CPPFLAGS" in item 1 should be "LOCAL_STATIC_LIBRARIES", while the "LOCAL_STATIC_LIBRARIES" in item 3 should be "APP_CPPFLAGS".

    We will update the doc accordingly in a future release.
    Here is an already fixed version:
    Android NDK

    For Android NDK Photon supports Visual Studio with WinGDB plugin on Windows as IDE, but you can also use makefiles, which will work on Windows and OS X. Linux is currently not supported.

    1. Add common-cpp-static-prebuilt and photon-cpp-static-prebuilt to "LOCAL_STATIC_LIBRARIES" in your applications Android.mk file.

    2. In your Projects Android.mk file add the following lines:
    $(call import-add-path, $(shell pwd)/../../../../Photon-cpp)
    $(call import-module,photon-cpp-prebuilt)

    3. Add -frtti to "APP_CPPFLAGS" in your applications Application.mk file.

    4. Set "APP_STL" in your applications Application.mk file to stlport_static, stlport_shared, gnustl_static or gnustl_shared.

    5. Add the following #include directive to your source-code:
    #include "Photon-cpp/inc/PhotonPeer.h"

    Please have a look at the demo project setups inside the sdk for an example of a working project setup.
    quite vague
    Would you like to go a bit more into detail about what information exactly you are missing?
  • victor
    Options
    Hi Kaiserludi,

    Thanks for the quick reply! Currently I don't have access to my work stuff, but one thing that comes to mind about stuff being vague is the lack of an example( a simple reference android.mk file?). The demo setups you mentioned are good, but I had to work around the file pathing to be definitively sure of where to unzip the AndroidNDK folder to, plus there were other dependencies in the demo packages that I'm not too certain that I should have included or not. (my lack of familiarity with the Android.mk file structure is at fault too! apologies).

    I'm thinking that having an example before and after android.mk file in the setup guide would be good, perhaps an indication of which directory level to unzip the package to.
  • victor
    Options
    Hi Kaiserludi,

    I've followed the instructions step by step, but i'm still getting this
    fatal error: Photon-cpp/inc/PhotonPeer.h: No such file or directory
    However, when I add this
    LOCAL_C_INCLUDES += $(LOCAL_PHOTON_ROOT)/Photon-cpp/inc
    to the android.mk file and use this
    #include "PhotonPeer.h"
    instead of the #include "Photon-cpp/inc/PhotonPeer.h" I can bypass the above error, but get an error with the dependencies inside PhotonPeer.h
    fatal error: Photon-cpp/inc/Internal/PeerBase.h: No such file or directory

    So I'm still getting problems linking the photon library to the my project, trying to figure it out.
  • victor
    Options
    I've still not gotten a good solution per se, but I've found a bypass of sorts, at least for people who've an existing cocos2dx project on Android properly set up(with eclipse). I followed the set up instructions as closely as possible first.

    Copy the contents of the of the Photon Folder ( Photon-cpp and Common-cpp) into the Classes folder(where all the native C++ source files reside) . I placed my Photon folder at the same level as my project(The folder having the same name as my project)

    Here's my Android.mk file
    ==========================================================================================
    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)

    LOCAL_MODULE := game_shared

    LOCAL_MODULE_FILENAME := libgame

    LOCAL_SRC_FILES := hellocpp/main.cpp \
    ../../Classes/Miscellaneous/AppDelegate.cpp \
    .
    .
    .
    "my cocos2dx c++ source files"

    LOCAL_PHOTON_ROOT := $(LOCAL_PATH)/../../../Photon-AndroidNDK_v3-2-2-0_SDK

    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

    LOCAL_STATIC_LIBRARIES := photon-cpp-static-prebuilt common-cpp-static-prebuilt

    LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static

    include $(BUILD_SHARED_LIBRARY)

    $(call import-add-path, $(LOCAL_PHOTON_ROOT)/Common-cpp)
    $(call import-add-path, $(LOCAL_PHOTON_ROOT)/Common-cpp/common-cpp-prebuilt)
    $(call import-module,common-cpp-prebuilt)

    $(call import-add-path, $(LOCAL_PHOTON_ROOT)/Photon-cpp)
    $(call import-add-path, $(LOCAL_PHOTON_ROOT)/Photon-cpp/photon-cpp-prebuilt)
    $(call import-module,photon-cpp-prebuilt)

    $(call import-module,CocosDenshion/android)
    $(call import-module,cocos2dx)
    $(call import-module,extensions)
    ==========================================================================================

    This is poor solution that mixes up the 2 different library structures, but I seem to have linked the photon successfully.I still need to figure out how to fix the dependencies and get a correct set up. Will still visit this thread.
  • Kaiserludi
    Options
    Hi victor.

    The doc pretends that the relative location of the libs to your game are the same as their relative location to the demos, which means $(LOCAL_PATH)/../../../..

    However in your setup telling from your pasted Android.mk file that relative location is $(LOCAL_PATH)/../../../Photon-AndroidNDK_v3-2-2-0_SDK.
    Therefor you will have to adjust the paths accordingly, which in your case means, changing LOCAL_C_INCLUDES
    into
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes $(LOCAL_PHOTON_ROOT)/

    Your should also return to
    #include "Photon-cpp/inc/PhotonPeer.h"
    as
    #include "PhotonPeer.h" won't work.
  • victor
    Options
    Hi KaiserLudi,

    Thanks! Things seem to work for
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes $(LOCAL_PHOTON_ROOT)/

    In my case though, because my project is a hybrid IOS/Android project, I needed to use #include "PhotonPeer.h", given the way IOS works(Does not accept relative paths) and use
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes $(LOCAL_PHOTON_ROOT)/inc

    Probably would need to include more of the photon subfolders as I continue developing. Thanks again.
  • Kaiserludi
    Options
    " given the way IOS works(Does not accept relative paths)"
    I don't see what you mean, as we have never had any relative path issues with iOS and are using them there extensively for years now.
    In fact we also use these relative include paths in our iOS SDK, which is getting built from the same codebase.
    You could have a look at the current 3.2.2.0 iOS SDK demo project settings to see, what you may do different then us that could cause your issues there.
  • victor
    Options
    Currently, if I use relative paths in my shared code base #include "Photon-cpp/inc/PhotonPeer.h" it throws an undefined error with an IOS build and none with the Android Build. On the other hand, using #include "PhotonPeer.h" has the opposite effect (error on Android and none on IOS). The reason that seems to occur is how the Xcode automatically searches and includes the subdirectories, while it must be done so manually in the Android.mk in Eclipse. Perhaps switching off this auto-search in Xcode would allow relative paths, but haven't had the time to test this.
  • Kaiserludi
    Options
    From the information that you have provided in this thread viewtopic.php?p=12931#p12931 I can tell you that this difference has nothing to do with Xcodes include behavior, but is just a difference between the client versions that you are using on iOS and on Android. We have introduced relative include paths just recently with the 3.2.2.0 release to reduce the risk of filename nameclashes, while all prior versions only include by filename without a path.
  • victor
    Options
    Hi,

    Returning to this thread about 2 years later, since the topic is the same...

    We've just recently upgraded the client side photon framework we're using from

    Photon-AndroidNDK_v3-0-3-11_SDK
    to
    Photon-AndroidNDK_v3-2-5-7_SDK

    and I've encountered an issue with setting up the photon framework. Here's the error being thrown in the console

    ...
    Using prebuilt externals
    Android NDK: ERROR:jni/../../../Photon-AndroidNDK_v3-2-5-7_SDK/Photon-cpp/photon-cpp-prebuilt/Android.mk:photon-cpp-static-prebuilt: The LOCAL_SRC_FILES for a prebuilt library should only contain one item
    ...

    I'm encountering a issue with importing the photon modules. Hoping to get an advice on where the file is being set up wrongly. Below are the relevant contents of my Android.mk file. Much thanks.

    ========================================================

    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)

    APP_TOOLCHAIN_VERSION := 4.7
    APP_USE_CPP0X := true
    APP_OPTIM := release
    LOCAL_CPPFLAGS := -std=c++0x
    LOCAL_CPPFLAGS += -DCOCOS2D_DEBUG=0

    all_static_libraries = common-cpp-static-prebuilt

    lib_suffix := ${APP_OPTIM}_android_${APP_ABI}

    lib_photon_cpp_static_name := photon-cpp-static_${lib_suffix}

    LOCAL_MODULE := game_shared
    LOCAL_MODULE_FILENAME := libgame

    LOCAL_SRC_FILES := hellocpp/main.cpp \
    //...
    //"my local src files"
    //...

    LOCAL_PHOTON_ROOT := $(LOCAL_PATH)/../../../Photon-AndroidNDK_v3-2-5-7_SDK
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
    //...
    //"my local c includes"
    //...
    LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes $(LOCAL_PHOTON_ROOT)

    LOCAL_STATIC_LIBRARIES := photon-cpp-static-prebuilt common-cpp-static-prebuilt
    LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static

    include $(BUILD_SHARED_LIBRARY)

    $(call import-add-path-optional, $(LOCAL_PHOTON_ROOT)/Common-cpp/src/android)
    $(call import-add-path-optional, $(LOCAL_PHOTON_ROOT)/Common-cpp)
    $(call import-add-path-optional, $(LOCAL_PHOTON_ROOT)/Photon-cpp/src/android)
    $(call import-add-path-optional, $(LOCAL_PHOTON_ROOT)/Photon-cpp)
    $(call import-module,CocosDenshion/android)
    $(call import-module,cocos2dx)
    $(call import-module,extensions)
    $(call import-module,android/native_app_glue)
    $(call import-module,photon-cpp-prebuilt)
    $(call import-module,common-cpp-prebuilt)

    ====================================================================================
  • victor
    Options
    Also, another note is that I am using

    android-ndk-r8-crystax-1
  • Kaiserludi
    Options
    Hi victor.

    Please remove the following two lines:
    $(call import-add-path-optional, $(LOCAL_PHOTON_ROOT)/Common-cpp/src/android)
    $(call import-add-path-optional, $(LOCAL_PHOTON_ROOT)/Common-cpp)
    
    and also this line
    $(call import-module,common-cpp-prebuilt)
    

    The Android.mk file of Photon-cpp already imports Common-cpp, so if your games Android.mk also imports Common-cpp itself, then that results in a double import which may cause the error that you are facing.
  • victor
    Options
    Hi Kaiserludi,

    Even after removing the common-cpp portions
    ...
    $(call import-add-path-optional, $(LOCAL_PHOTON_ROOT)/Photon-cpp/src/android)
    $(call import-add-path-optional, $(LOCAL_PHOTON_ROOT)/Photon-cpp)
    $(call import-module,CocosDenshion/android)
    $(call import-module,cocos2dx)
    $(call import-module,extensions)
    $(call import-module,android/native_app_glue)
    $(call import-module,photon-cpp-prebuilt)
    ...

    a similiar error occurs

    ...
    Using prebuilt externals
    Android NDK: ERROR:jni/../../../Photon-AndroidNDK_v3-2-5-7_SDK/Photon-cpp/photon-cpp-prebuilt/Android.mk:photon-cpp-static-prebuilt: The LOCAL_SRC_FILES for a prebuilt library should only contain one item
    ...

    Still figuring it out currently.
  • victor
    Options
    Hi KasierLudi,

    I managed to get the mk files to link up correctly by modifying
    ../Photon-AndroidNDK_v3-2-5-7_SDK/Photon-cpp/photon-cpp-prebuilt/Android.mk

    from
    $(call import-add-path, $(shell pwd)/../../../../Common-cpp/src/android)
    $(call import-add-path, $(shell pwd)/../../../../Common-cpp)
    to
    $(call import-add-path, $(LOCAL_PATH)/../../Common-cpp/src/android)
    $(call import-add-path, $(LOCAL_PATH)/../../Common-cpp)

    and adding
    APP_CPPFLAGS := common-cpp-static-prebuilt photon-cpp-static-prebuilt
    to my Android.mk
    (Not adding results in a clang error:
    clang++: error: no such file or directory: 'libphoton-cpp-static_release_android_armeabi-v7a.a')

    Right now I've had to make my build only compile for one armeabi architecture. Leaving
    APP_ABI := armeabi armeabi-v7a in Application.mk results in a similiar error from before occurring

    Android NDK: ERROR:jni/../../../Photon-AndroidNDK_v3-2-5-7_SDK/Photon-cpp/photon-cpp-prebuilt/Android.mk:photon-cpp-static-prebuilt: The LOCAL_SRC_FILES for a prebuilt library should only contain one item
  • victor
    Options
    Is there any advice you would have for this issue?
  • Kaiserludi
    Options
    "APP_ABI := armeabi armeabi-v7a in Application.mk"
    This is not supported with the Photon AndroidNDK 3.x buildchain (did you achieve that with 3.0.3.11? I don't think that would ever have worked without modifying the Android.mk files of the Photon libs themselves in any release prior to 4.0.0.0)
    You would either have to use one separate Application.mk file per architecture and configuration, that each load a different version of the Photon libraries. like the demos do it, or you would need to modify the Android.mk files of the Photon libs themselves to support this (and I am afraid I won't be of much help with that task).

    However using just one Application.mk for all architectures and configs is supported with the Photon AndroidNDK 4.x buildchain, so it might be the best option, if you update from your current version 3.0.3.11 straight up to the latest v4 release 4.0.3.1 instead of just to the latest v3 release 3.2.5.7.