EOS SDK for Android

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

7 mins to read

Supported Android Release Versions

The table below lists the Android release version which each EOS SDK release version supports:

EOS SDK Release VersionAndroid Release Version
EOS SDK 1.10.2 - 1.15.5supports6.0 (API level 23)

Supported Versions for Unity

The table below lists the minimum Android release version which each EOS SDK release version supports for Unity:

EOS SDK Release VersionAndroid Release Version
EOS SDK 1.15.2 - 1.15.5supports6.0 (API level 23)

Set up the EOS SDK for Android

This guide describes how to do the following:

  • Add the EOS SDK to an Android Studio project.
  • Ensure that your build system recognizes the EOS SDK.
  • Handle Android-specific initialization of the EOS SDK.

Before implementing the EOS SDK with Android, see the documentation on general guidelines and references for information on platform implementation.

1. Prerequisites

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. Add the 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-v7athat 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 game's build.gradle file, which is 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):

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

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

3. Include the EOS 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.

How to use 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 must let CMake know where the library is located.

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

CMakeLists.txt

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

CMakeLists.txt

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

At this point, sync gradle and you should be able to import EOS SDK symbols into your C++ project and move to the Android-Specific Initialize Options section.

For more information about using CMake, refer to https://developer.android.com/ndk/guides/cmake.

How to use EOS With ndk-build

If you are using ndk-build for your project, you will need to add EOS SDK as a module to your Android.mk file. A basic Android.mk file would look like this:

Android.mk

This file defines a hello-jni module with a single .c file as its source. You need to define a similar module in this file for EOS SDK, such as the following:

Android.mk

In this example, the zip file was inflated in the same folder as the Android.mk file. If you prefer the files elsewhere you can replace the LOCAL_PATH with the correct path instead.

To use the EOS SDK module from the hello-jni module, you will need to link them. You can do this by adding the sdk as a LOCAL_SHARED_LIBRARIES entry. Additionally, make sure c++_shared is also referenced.

Android.mk

At this point, the hello-jni module should have access to the exported symbols from the EOS SDK!

The full demo Android.mk file is provided below. This will need to be adapted for your specific use case.

Android.mk

For more information about ndk-build, refer to https://developer.android.com/ndk/guides/ndk-build.

4. Android-Specific System Initialize Options

For the EOS SDK to function, you must load native library with System.loadLibrary (Some game engines do this automatically when importing plugins):

And pass application context to the SDK as follows:

In the login example, we do this in the onCreate of the MainActivity class.

The following example of initializing the EOS SDK on Android can be adapted for specific use cases:

To setup optional directory paths for disk access, the EOS SDK has platform-specific System Initialize Options for Android:

The following method is for SDK versions 1.10 and older. For SDK versions 1.11 and above, use the above method.

For EOS SDK versions 1.10 and older, the System Initialize Options are defined as EOS_Android_InitializeOptions and require a reference to the JavaVM with optional directory paths for disk access.

For EOS SDK Java-side to function, you need to pass the application context to it as follows:

In the login example, we do this in onCreate of the MainActivity class.

To get the correct values for these options, you should pass in the associated values over JNI. With a reference to a JNIEnv* you can access the JavaVM easily.

Here is an example of a full initialization of the EOS SDK on Android. This will need to be adapted for specific use-cases.

5. How to receive Login Intent

For the EOS SDK to receive the correct login intent, you must supply your client ID in Strings.xml.

The client ID must be lowercase. Scheme matching in the Android framework is case-sensitive, and you should always specify schemes using lowercase letters.

In res/values/strings.xml setup eos_login_protocol_scheme with your clientId: