---
id: android-getting-started
title: Getting Started
slug: /cppsdk/android/getting-started
sidebar_position: 1
custom_edit_url: https://github.com/modio/modio-sdk-internal/blob/develop/platform/android/doc/getting-started.mdx
---

## Android SDK/NDK Versions

The mod.io Android SDK is built against NDK version NDK r23c, shipped with Visual Studio 2022's Android workload and supports the arm64-v8a ABI.

## Compiling for Android

Currently, the mod.io SDK can only be used from native Android applications being built with CMake on Windows. There is no support for the AGDE for Visual Studio. mod.io SDK method calls are not available from Java.  You can follow the CMake Integration documentation for how to configure your native CMake project to use the SDK.

## Initializing the Android SDK

Prior to initializing the mod.io SDK via `Modio::InitializeAsync`, you have to pass a few initialization parameters to the SDK for Android specific support.

1. Pass mod.io the JNI VM and an optional reference to the global ClassLoader using `Modio::InitializeAndroidJNI(vm, nullptr);`. Generally you should do this in your `JNI_OnLoad` method. If you don't provide a reference to the native classloader, the SDK will attempt to discover and create one itself.

2. Pass mod.io a reference to your native main Activity using `Modio::SetGlobalActivity(JavaObject);`. You can do this either in a native event from Java, or anytime in your startup process if you have a reference to the native activity cached.

3. Call `Modio::InitializeAndroid();` for mod.io to initialize and setup its JNI bindings.

### Authentication

There are two ways that you can perform Google SSO, either via a server-side auth code which the mod.io service will exchange for an ID Token, or directly using an ID token.

#### Sever Auth Code

Obtain a Server Auth Code from Google Play Games Services (v1 only) or the Google Sign-In Client library, ensuring you request Email access and the Profile scope.

```java
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
                .requestScopes(new Scope(Scopes.PROFILE))
                .requestEmail()
                .requestServerAuthCode(OAUTH_CLIENT_ID)
                .build();
```

You can then show the Google Sign-In Intent to prompt users to consent to the OAuth scopes you are requesting, and obtain the server auth code in the callback.

```java
    SignInClient = GoogleSignIn.getClient(this, signInOptions);
    startActivityForResult(SignInClient.getSignInIntent(), RC_SIGN_IN);

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == RC_SIGN_IN) {
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(intent);

            try {
                GoogleSignInAccount account = task.getResult(ApiException.class);
                serverSideAuthCode = account.getServerAuthCode();
            }
        }
    }
```

Once you receive the Server Auth Code, you can authenticate using `Modio::AuthenticateUserExternalAsync`, passing `Modio::AuthenticationProvider::GoogleServerSideToken` as the authentication provider. This indicates to mod.io that this is a server side token that should be exchanged for an ID Token by the backend.

Ensure that you have configured your OAuth client ID and secret on your games authentication providers page.

You can read more about Google Play Services sign-in at https://developers.google.com/games/services/common/concepts/v1/sign-in

#### ID Token

You can also directly request an ID Token using Google Credential Manager, and use this to authenticate.

Once you receive the ID Token, you can authenticate using `Modio::AuthenticateUserExternalAsync`, passing `Modio::AuthenticationProvider::GoogleIDToken` as the authentication provider. This indicates to mod.io that this is is an ID token that can be directly used.