Using EOS SDK on Android

How to implement EOS SDK in an Android project with Android Studio

7 mins to read

This guide explains how to add the Epic Online Services (EOS) SDK to an Android Studio project, ensure that your build system recognizes the SDK, and handle Android-specific initialization of the SDK.

Before implementing the SDK with Android, be sure to review the general guidelines and references for platform implementation.

1. Required Setup

This guide assumes that you already have an Android Studio project that can build C/C++ code with the Android NDK. If you do not have a project set up, follow the guides at https://developer.android.com/ndk/guides to get started. This guide also assumes that you use Gradle to build your project. Other build tools should also work, but are not officially supported.

The EOS SDK requires libc++_shared to be bundled with your app. If it is your desired Standard Template Library (STL), refer to https://developer.android.com/ndk/guides/cpp-support#selecting_a_c_runtime for information about how to bundle it in your .apk or .aab.

If you are using a different STL you will still need to bring in the associated libc++_shared library for your NDK release. You can find the .so files in your ndk folder at sources\cxx-stl\llvm-libc++\libs\{arch}\. These will need to be included in the final build through your build tool.

2. Adding EOS SDK to Your Android Studio Project

The SDK download from the Developer Portal provides a zip file containing the following artifacts:

  • An include folder containing all headers exposed from the EOS SDK.
  • A lib folder containing EOS SDK .so files built for arm64-v8a and armeabi-v7a that can be used when building your app.
  • The EOSSDK.aar file, which will automatically bundle the correct library with your app and add both required permissions and accompanying java code into your project.

Regardless of which build system you use, you will need to bring EOSSDK.aar into your project as a module. To do that, complete the following steps:

  1. Click File > New > New Module…

    Select New Module in the File menu
  2. Select Import .JAR/.AAR Package from the list of options and click Next.

    Select Import .JAR/.AAR Package
  3. Select the .aar file from the extracted zip file. The Subproject Name should automatically fill in to say "EOSSDK". If not, set it manually or choose an alternate name. EOSSDK should now show up as an imported module in your project.

  4. Open your app’s build.gradle file, which will be located inside the EOSSDK folder.

    EOSSDK appears in the project with the build.gradle file.
  5. In the dependencies block add implementation androidx.security:security-crypto:1.0.0-rc01 and implementation project(path: :EOSSDK):

dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.security:security-crypto:1.0.0-rc01'
implementation project(':EOSSDK')
}

The SDK is now imported into your project and will be included in your builds! The .aar file will automatically handle bringing the correct .so file into the .apk/.aab during the build process.

The following sections will explain how to directly integrate the C libraries within the SDK.

3. Including the SDK With Your Build System

You can add the EOS SDK to your project using either CMake or ndk-build, which are both officially supported build systems that can be used with the NDK. This section will provide information about how to bring the SDK into your project using these build systems.

Using EOS With CMake

If you are using CMake in your project, you should have a CMakeLists.txt file in your project. To bring the EOS SDK into your NDK project you will need to let CMake know where the library is located.

To do this, edit the CMakeLists.txt file and add the following commands:

CMakeLists.txt

add_library(EOSSDK SHARED IMPORTED)
set(EOSSDKDIR PUT_PATH_TO_EXPANDED_ZIP_HERE)
set_property(TARGET EOSSDK PROPERTY IMPORTED_LOCATION ${EOSSDKDIR}/lib/${ANDROID_ABI}/libEOSSDK.so)
set_property(TARGET EOSSDK PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${EOSSDKDIR}/include/)

If you expanded the zip in the same directory as the CMakeLists.txt, it would look like this:

CMakeLists.txt

add_library(EOSSDK SHARED IMPORTED)
set(EOSSDKDIR ${CMAKE_SOURCE_DIR})
set_property(TARGET EOSSDK PROPERTY IMPORTED_LOCATION ${EOSSDKDIR}/lib/${ANDROID_ABI}/libEOSSDK.so)
set_property(TARGET EOSSDK PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${EOSSDKDIR}/include/)

Finally, make sure the EOS SDK is linked with the appropriate library in your project. In an Android Studio C++ project created in the New Project Wizard, that would look like this:

CMakeLists.txt

target_link_libraries( # Specifies the target library.
native-lib
#Links the target library to the EOSSDK
EOSSDK
# Links the target library to the log library
# included in the NDK.
${log-lib} )