Home | Documentation | Atomic Chat | Github

Platform-specific build using only cpp api


#1

Hi guys.
I have been searching for some good alternative to cocos2d-x (working with it is a mess sometimes) in case of transparent c++ development, and AGE looks really cool. Actually I have a very thin framework in c++ for game logic implementation (ecs approach + some helpers) and I want to use it for all core game logic and AGE for all other things (scene graph, networking, ui, etc). The main point is I can create cmake based project with AGE as static library and be happy with development under linux. But I totally have no idea how to ship it to some android/ios device. Atomic editor do it automatically using some internal magic. So could you tell please, can I reuse that logic somehow to install my app on the mobile devices? Or maybe there’s a dedicated approach for such things? Thank you a lot!


#2

Okay, do you at least have plans for something like that?
There’re some thoughts about it in Just Code roadmap. Actually the way how it is handled in cocos2d-x is not very convenient. Just imagine you are making cross-platform game. All core game logic is implemented in cpp. Each platform has its own dev environment (xcode, android studio, visual studio, make), and if you want to keep all platforms compilable, you should add new files (remove unused files) to each platform-specific project files, configure compilation flags N times and so on. Instead there should be better to have some project generator for each platform, so you can configure source files/directories, header search paths, resources directory and others, and it will generate full project for each ide (like cmake does, but it cannot handle all actual platforms with their specific stuff, like android). I’m working in one gamedev studio, we make mobile games for ios/android/win mobile mostly, we have such tool, it can generate projects for iOS, tvOS, android studio, visual studio and cmake. I can say that it is absolutely awesome when you can just type ./build_tool apple ios development debug, and it will generate iOS project (for example). Maybe I can help you with this task a bit.
@JoshEngebretson AFAIK you have some experience in this field (link), and I’m sure you have some thoughts about it.
What do you think guys?
Thank you!


#3

At least for android you are supposed to crosscompile. It produces apk which you can ship. Follow these instructions to set up android build in c+±only project:

  1. Get Android.cmake toolchain from Urho3D and put it to ${CMAKE_SOURCE_DIR}/CMake.
  2. Get android build files and put it to your CMAKE_SOURCE_DIR/Android.
  3. Put macro i wrote somewhere in your CMake build scripts:
macro(setup_android_target)
    if (NOT ANDROID)
        message(ERROR "Can not add android target in non-android build.")
    endif ()

    cmake_parse_arguments(PARAM "" "DEBUG;TARGET;SOURCE_DIR" "RESOURCE_DIRS" ${ARGN})
    # Target output
    set(LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PARAM_SOURCE_DIR}/libs/${ANDROID_ABI})
    file(MAKE_DIRECTORY ${LIBRARY_OUTPUT_DIRECTORY})

    # Copy gdbserver
    if (PARAM_DEBUG)
        string(REPLACE "armeabi" "arm" NDK_ANDROID_ABI "${ANDROID_ABI}")
        file(COPY ${ANDROID_NDK}/prebuilt/android-${NDK_ANDROID_ABI}/gdbserver/gdbserver DESTINATION ${LIBRARY_OUTPUT_DIRECTORY})
    endif ()

    # Link game assets in android assets dir
    file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/${PARAM_SOURCE_DIR}/assets)
    foreach (I IN LISTS PARAM_RESOURCE_DIRS)
        get_filename_component(BASENAME "${I}" NAME)
        symlink(${I} ${CMAKE_BINARY_DIR}/${PARAM_SOURCE_DIR}/assets/${BASENAME})
    endforeach ()

    file(GLOB ANDROID_BUILD_FILES RELATIVE "${CMAKE_SOURCE_DIR}/${PARAM_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/${PARAM_SOURCE_DIR}/*")
    list(REMOVE_ITEM ANDROID_BUILD_FILES assets)
    # Link build files and dirs except for assets
    foreach (I ${ANDROID_BUILD_FILES})
        symlink("${CMAKE_SOURCE_DIR}/${PARAM_SOURCE_DIR}/${I}" "${CMAKE_BINARY_DIR}/${PARAM_SOURCE_DIR}/${I}")
    endforeach ()
    # Link android-exclusive assets if any
    file(GLOB ANDROID_BUILD_FILES RELATIVE "${CMAKE_SOURCE_DIR}/${PARAM_SOURCE_DIR}/assets" "${CMAKE_SOURCE_DIR}/${PARAM_SOURCE_DIR}/assets/*")
    foreach (I ${ANDROID_BUILD_FILES})
        symlink("${CMAKE_SOURCE_DIR}/${PARAM_SOURCE_DIR}/assets/${I}" "${CMAKE_BINARY_DIR}/${PARAM_SOURCE_DIR}/assets/${I}")
    endforeach ()

    include_directories("${Atomic_SOURCE_DIR}/Source/ThirdParty/SDL/include")
    list(APPEND SOURCE_FILES "${CMAKE_SOURCE_DIR}/dep/AtomicGameEngine/Source/ThirdParty/SDL/src/main/android/SDL_android_main.c")
    add_library(Blocktastic SHARED ${SOURCE_FILES})
    set_property(TARGET ${PARAM_TARGET} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_DIRECTORY})
    add_custom_command(TARGET ${PARAM_TARGET}
        POST_BUILD
        COMMAND "${ANDROID_SDK}/tools/android" ARGS update project -p .
        COMMAND ant ARGS debug
        COMMAND "${ANDROID_SDK}/platform-tools/adb" ARGS install -r "${CMAKE_BINARY_DIR}/${PARAM_SOURCE_DIR}/bin/${CMAKE_PROJECT_NAME}-debug.apk"
        WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/${PARAM_SOURCE_DIR}"
        COMMENT "Building android apk"
        )
endmacro()

  1. Make sure ANDROID_SDK and ANDROID_NDK environment variables point to SDK and NDK (i use NDK v13b).
  2. Setup your android target (main game executable):
if (ANDROID)
    setup_android_target(
        TARGET Blocktastic
        SOURCE_DIR Android
        DEBUG "${DEBUG}"
        RESOURCE_DIRS
            ${CMAKE_SOURCE_DIR}/bin/GameData
            ${CMAKE_SOURCE_DIR}/dep/AtomicGameEngine/Resources/CoreData
    )
else ()
    add_executable (Blocktastic ${APPLICATION_SYSTEM} ${SOURCE_FILES})
endif ()
  1. Run cmake with -DANDROID=1 -DANDROID_NATIVE_API_LEVEL=android-21 -DANDROID_ABI=armeabi -DCMAKE_TOOLCHAIN_FILE=CMake/Android.cmake and build it.

If you have it all done right after building your project it should be sent to connected device as well. If you do not wish to have built application uploaded to device remove add_custom_command() from end of the macro.