# Android SDK

## System Requirements <a href="#undefined" id="undefined"></a>

The system requirements for using the **GAMEPOT Android SDK** are as follows:

* Minimum Requirements: Android Level 24 or higher (If you need support for lower versions of Android, please contact <dl_help_game@navercorp.com>.)

## SDK Installation and Environment Configuration <a href="#sdk" id="sdk"></a>

After installing the Android SDK, you can configure the environment to integrate the GAMEPOT dashboard with your game and use the necessary features for game development.

The GAMEPOT SDK supports the following languages:

* Korean, English, Italian, Thai, Vietnamese, Japanese, Chinese (Simplified/Traditional), Indonesian, German, Spanish, French.

When running the app, the SDK will display the supported language based on the device’s language settings. If a language is not supported, it will default to English.

### SDK Installation <a href="#sdk" id="sdk"></a>

To install the GAMEPOT Android SDK and set up the project, follow these steps:

1. Log in to the dashboard with an administrator account.
2. Add the Nbase SDK to the `bundle.gradle` or `bundle.gradle.kts` file.
3. Starting from GAMEPOT 3.0, external libraries can be easily integrated through Gradle settings.

### **Kotlin Gradle** Configuration

1. Add the following definition to the `settings.gradle.kts` file of the project.

```kotlin
dependencyResolutionManagement {
    repositories {
        ...
        google()
        // nbase repo
        maven(url = "https://repo.nbase.io/repository/nbase-releases")
    }
}
```

2. Add SDK dependencies to the `build.gradle.kts` file of the project (Module: app).

```kotlin
dependencies {
...
    implementation("com.google.code.gson:gson:2.10")
    implementation("androidx.security:security-crypto:1.0.0")
    implementation("com.apollographql.apollo3:apollo-runtime:4.0.0-beta.4")
    implementation("io.socket:socket.io-client:2.1.0")
    implementation("io.nbase:nbasesdk:3.0.78")
}
```

Example: If using Google login and Google Play Store payment.

```kotlin
 dependencies {
...
    implementation("com.google.code.gson:gson:2.10")
    implementation("androidx.security:security-crypto:1.0.0")
    implementation("com.apollographql.apollo3:apollo-runtime:4.0.0-beta.4")
    implementation("io.socket:socket.io-client:2.1.0")
    implementation("io.nbase:nbasesdk:3.0.78")
    implementation("io.nbase:nbase-adapter-provider-google:3.0.4")
    implementation("io.nbase:nbase-adapter-billing-googleplay:3.0.3")
    implementation("com.google.android.gms:play-services-auth:20.7.0")
    implementation("com.android.billingclient:billing-ktx:6.1.0")
}
```

### **Java Gradle** Configuration

1. Add the definition to the `build.gradle` file of the project (Module: project).

````Groovy
allprojects {
    repositories {
        ...
        google()
        // nbase repo
        maven { url "https://repo.nbase.io/repository/nbase-releases" }
    }
}

2. 프로젝트에 (Module : app)의 build.gradle 파일에 SDK 종속성을 추가합니다.
```Groovy
dependencies {
...
    implementation("com.google.code.gson:gson:2.10")
    implementation("androidx.security:security-crypto:1.0.0")
    implementation("com.apollographql.apollo3:apollo-runtime:4.0.0-beta.4")
    implementation("io.socket:socket.io-client:2.1.0")
    implementation("io.nbase:nbasesdk:3.0.78")
}
````

Example: If using Google login and Google Play Store payment.

```Groovy
 dependencies {
...
    implementation("com.google.code.gson:gson:2.10")
    implementation("androidx.security:security-crypto:1.0.0")
    implementation("com.apollographql.apollo3:apollo-runtime:4.0.0-beta.4")
    implementation("io.socket:socket.io-client:2.1.0")
    implementation("io.nbase:nbasesdk:3.0.78")
    implementation("io.nbase:nbase-adapter-provider-google:3.0.4")
    implementation("io.nbase:nbase-adapter-billing-googleplay:3.0.3")
    implementation("com.google.android.gms:play-services-auth:20.7.0")
    implementation("com.android.billingclient:billing-ktx:6.1.0")
}
```

### Library List

<table><thead><tr><th>Name</th><th width="83">Version</th><th width="145">Type</th><th>Dependeny modules</th></tr></thead><tbody><tr><td>io.nbase:nbasesdk</td><td>3.0.78</td><td>GAMEPOT Base Module</td><td>X</td></tr><tr><td>io.nbase:nbase-adapter-provider-google</td><td>3.0.4</td><td>Google Login</td><td>com.google.android.gms:play-services-auth:20.7.0</td></tr><tr><td>io.nbase:nbase-adapter-provider-apple</td><td>3.0.3</td><td>Apple Login</td><td></td></tr><tr><td>io.nbase:nbase-adapter-provider-facebook</td><td>3.0.2</td><td>Facebook Login</td><td>com.facebook.android:facebook-login:latest.release</td></tr><tr><td>io.nbase:nbase-adapter-provider-naver</td><td>3.0.1</td><td>NAVER Login</td><td></td></tr><tr><td>io.nbase:nbase-adapter-provider-line</td><td>3.0.1</td><td>Line Login</td><td></td></tr><tr><td>io.nbase:nbase-adapter-provider-x</td><td>3.0.1</td><td>X Login</td><td></td></tr><tr><td>io.nbase:nbase-adapter-billing-googleplay</td><td>3.0.3</td><td>Google Store</td><td>com.android.billingclient:billing-ktx:6.1.0</td></tr><tr><td>io.nbase:nbase-adapter-billing-one</td><td>3.0.1</td><td>ONEStore</td><td></td></tr><tr><td>io.nbase:nbase-adapter-billing-galaxy</td><td>3.0.1</td><td>Galaxy Store</td><td></td></tr><tr><td>io.nbase:nbase-adapter-billing-amazon</td><td>3.0.1</td><td>Amazon Store</td><td></td></tr></tbody></table>

Email and guest login are applied to the base module.

## Preparation Steps <a href="#undefined" id="undefined"></a>

1. You can copy the Project ID and Project Key from the Dashboard → Project Settings.
2. Environment settings for login, store, and integration can all be added/modified from the Dashboard → Project Settings.
3. For each login method, refer to the \[[Login Authentication Settings](/basics/gamepot-3.0/images-and-media/editor/login-authentication-settings.md)], configure it in the console, and add it to the dashboard.
4. For in-app payments, refer to the \[[Store Settings](/basics/gamepot-3.0/images-and-media/editor/store-settings.md)], configure it in the console, and add it to the dashboard.
5. Please register items for each store for in-app payments. Add them in the Dashboard → Payment → In-App section.

## Initialization <a href="#undefined" id="undefined"></a>

To initialize, add the following code to the object used in the first scene that loads when the game starts.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import com.nbase.sdk.NBase
import com.nbase.sdk.Store

 NBase.initialize(activity, projectId, projectKey, [StoreId], [language], [region]) { init, e ->
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        Log.e("NBase", init)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
import com.nbase.sdk.NBase;
import com.nbase.sdk.Store;

NBase nBase = NBase.INSTANCE;
nBase.initialize(activity, projectId, projectKey, Store.GOOGLE, language, region, (init, e) -> {
    if (e != null) {
        Log.e("NBase", "initialize fail: " + e.getMessage());
    } else {
        Log.e("NBase", "initialize success: " + init.toString());
    }
    return null;
});
```

{% endtab %}
{% endtabs %}

* Parameter

<table><thead><tr><th width="208">Key</th><th width="316">Description</th><th>Required</th></tr></thead><tbody><tr><td>projectId</td><td>Dashboard → Project Settings</td><td>O</td></tr><tr><td>projectKey</td><td>Dashboard → Project Settings</td><td>O</td></tr><tr><td>storeId</td><td>Refer to the table below</td><td>O</td></tr><tr><td>language</td><td>Language (en,ko,jp...)</td><td>O</td></tr><tr><td>region</td><td>Region (kr, jp, sg, us, eu, preview)</td><td>O</td></tr></tbody></table>

| Key                     | Description  |
| ----------------------- | ------------ |
| Store.GOOGLE.ToString() | Google Store |
| Store.ONE.ToString()    | ONEStore     |
| Store.GALAXY.ToString() | Galaxy Store |
| Store.AMAZON.ToString() | Amazon Store |
| Store.HUAWEI.ToString() | Huawei Store |

* Callback

| Key        | Type    | Description  |
| ---------- | ------- | ------------ |
| status     | Boolean | Status       |
| language   | String  | Language     |
| country    | String  | Country      |
| remote\_ip | String  | IP           |
| platform   | String  | Platform     |
| sandbox    | Boolean | Sandbox Mode |

## Login <a href="#undefined" id="undefined"></a>

To use the SDK login functionality that is triggered when the login button is clicked, depending on the login UI implemented by the developer, please use the following code.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import com.nbase.sdk.Provider

NBase.signIn(activity, Provider.GOOGLE.toString()) { user, e -> 
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        Log.e("NBase", user)
    }
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    NBase.onActivityResult(requestCode, resultCode, data)
}
```

{% endtab %}

{% tab title="Java" %}

```java
import com.nbase.sdk.Provider;

NBase nBase = NBase.INSTANCE;
nBase.signIn(activity, Provider.GOOGLE.toString(), (user, e) -> {
    if (e != null) {
        Log.e("NBase", "signIn fail: " + e.getMessage());
    } else {
        Log.e("NBase", "signIn success: " + user.toString());
    }
    return null;
});

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    nBase.onActivityResult(requestCode, resultCode, data);
}
```

{% endtab %}
{% endtabs %}

* Parameter

| Key                           | Description |
| ----------------------------- | ----------- |
| Provider.GOOGLE.ToString()    | Google      |
| Provider.ANONYMOUS.ToString() | Guest       |
| Provider.FACEBOOK.ToString()  | Facebook    |
| Provider.APPLE.ToString()     | Apple       |
| Provider.KAKAO.ToString()     | Kakao       |
| Provider.PLAYGAME.ToString()  | Play Game   |
| Provider.STEAM.ToString()     | Steam       |
| Provider.X.ToString()         | X           |
| Provider.LINE.ToString()      | Line        |
| Provider.NAVER.ToString()     | NAVER       |
| Provider.GITHUB.ToString()    | Github      |
| Provider.MICROSOFT.ToString() | Microsoft   |
| Provider.HUAWEI.ToString()    | Huawei      |

* Callback

| Key         | Type   | Description   |
| ----------- | ------ | ------------- |
| id          | String | User ID       |
| socialId    | String | Social ID     |
| name        | String | Name          |
| nickname    | String | Nickname      |
| email       | String | Email         |
| token       | String | Token         |
| age         | Int    | Age           |
| birth       | String | Date of Birth |
| sex         | String | Gender        |
| profile     | String | Profile URL   |
| mobile      | String | Phone Number  |
| customField | String | Custom Field  |

#### Automatic Login (Optional)

After initialization, the system attempts automatic login using the last authentication method the user logged in with.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
NBase.signInLastLoggedIn(activity) { user, e ->
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        Log.e("NBase", user)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
NBase nBase = NBase.INSTANCE;
nBase.signInLastLoggedIn(activity, (user, e) -> {
    if (e != null) {
        Log.e("NBase", "signInLastLoggedIn fail: " + e.getMessage());
    } else {
        Log.e("NBase", "signInLastLoggedIn success: " + user.toString());
    }
    return null;
});
```

{% endtab %}
{% endtabs %}

#### Self-ID and Password Authentication (Optional)

This authentication method allows users to log in using their email address and password. It performs user authentication based on the user's email address and password. This feature plays an important role in traditional email/password-based authentication systems.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
NBase.signInWithPassword(activity, username, password) { user, e ->
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        Log.e("NBase", user)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
NBase nBase = NBase.INSTANCE;
nBase.signInWithPassword(activity, username, password, (user, e) -> {
    if (e != null) {
        Log.e("NBase", "signInWithPassword fail: " + e.getMessage());
    } else {
        Log.e("NBase", "signInWithPassword success: " + user.toString());
    }
    return null;
});
```

{% endtab %}
{% endtabs %}

#### Login with Credentials (Optional)

This feature is used to handle user login using authentication credentials obtained through various methods (such as email and password, social media accounts, phone numbers, etc.). It facilitates the implementation of diverse authentication methods and enables login to Gamepot.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
NBase.signInWithCredential(activity, Provider.GOOGLE.ToString(), providerToken) { user, e ->
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        Log.e("NBase", user)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
NBase nBase = NBase.INSTANCE;
nBase.signInWithCredential(activity, Provider.GOOGLE.toString(), providerToken, (user, e) -> {
    if (e != null) {
        Log.e("NBase", "signInWithCredential fail: " + e.getMessage());
    } else {
        Log.e("NBase", "signInWithCredential success: " + user.toString());
    }
    return null;
});
```

{% endtab %}
{% endtabs %}

## Logout <a href="#undefined" id="undefined"></a>

To use the SDK logout function, please use the code below.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
NBase.signOut() { status, e ->
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        Log.e("NBase", status)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
NBase nBase = NBase.INSTANCE;
nBase.signOut((status, e) -> {
    if (e != null) {
        Log.e("NBase", "signOut fail: " + e.getMessage());
    } else {
        Log.e("NBase", "signOut success: " + status);
    }
    return null;
});
```

{% endtab %}
{% endtabs %}

* Callback

<table><thead><tr><th width="232">Key</th><th width="233">Type</th><th>Description</th></tr></thead><tbody><tr><td>status</td><td>Boolean</td><td>Success Status</td></tr></tbody></table>

## Payment <a href="#undefined" id="undefined"></a>

Before making a payment, you must configure the settings for each store according to the store's requirements in the \[[Store Settings](/basics/gamepot-3.0/images-and-media/editor/store-settings.md)]. Additionally, if items have not been added in the Dashboard → Payment → In-App section, the error 'ProductID not found' will occur.

### Fetch In-App Information

When making a payment, you need to display payment information and local currency details on the screen. You can retrieve the current payment currency, name, and other details using the functions below. If the information is not fetched correctly, please check the console settings.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import com.nbase.sdk.Store

NBase.getProductItems() {products, e -> 
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        // In-app Item Information
        Log.e("NBase", products)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
NBase nBase = NBase.INSTANCE;
nBase.getProductItems((products, e) -> {
    if (e != null) {
        Log.e("NBase", "getProductItems fail: " + e.getMessage());
    } else {
        if (products != null) {
            Log.e("NBase", "getProductItems success: " + products.toString());
        }
    }
    return null;
});
```

{% endtab %}
{% endtabs %}

* Callback

| Key                | Type   | Description         |
| ------------------ | ------ | ------------------- |
| id                 | String | ID                  |
| productName        | String | Product Name        |
| price              | Float  | Product Price       |
| productId          | String | Product Unique ID   |
| productType        | String | Product Type        |
| productDescription | String | Product Description |
| currency           | String | Currency Unit       |

### Payment Request

You can request a payment using the `productId` from the fetched in-app information.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import com.nbase.sdk.Store

NBase.purchase(activity, Store.GOOGLE, [productId], [metadata], [options]) { purchase, e -> 
    if (e != null) {
        Log.e("NBase", e.message)
    } else {
        Log.e("NBase", purchase)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
import com.nbase.sdk.Store;

NBase nBase = NBase.INSTANCE;
nbase.purchase(activity, Store.GOOGLE, productId, metadata, options, (purchase, e) -> {
    if (e != null) {
        Log.e("NBase", "purchase fail: " + e.getMessage());
    } else {
        if (purchase != null) {
            Log.e("NBase", "purchase success: " + purchase.toString());
        }
    }
    return null;
});
```

{% endtab %}
{% endtabs %}

* Parameter

<table><thead><tr><th width="153">Key</th><th width="474">Description</th><th>Required</th></tr></thead><tbody><tr><td>ProductId</td><td>Product ID (Dashboard → Payment → In-App Items)</td><td>O</td></tr><tr><td>Metadata</td><td>Metadata</td><td>X</td></tr><tr><td>Options</td><td>Payment Option Features</td><td>X</td></tr></tbody></table>

| Key                     | Description  |
| ----------------------- | ------------ |
| Store.GOOGLE.ToString() | Google Store |
| Store.ONE.ToString()    | ONEStore     |
| Store.GALAXY.ToString() | Galaxy Store |
| Store.AMAZON.ToString() | Amazon Store |
| Store.HUAWEI.ToString() | Huawei Store |

* Callback

| Key              | Type   | Description            |
| ---------------- | ------ | ---------------------- |
| id               | String | ID                     |
| orderId          | String | Oder ID                |
| storeId          | String | Store ID               |
| productId        | String | Product ID             |
| billingKey       | String | Billing Key            |
| signature        | String | Signature              |
| originalJson     | String | Original JSON          |
| developerPayload | String | Developer Payload      |
| packageName      | String | Package Name           |
| isAcknowledged   | bool   | Confirmation Status    |
| purchaseState    | String | Purchase Status        |
| purchaseTime     | String | Purchase Time          |
| quantity         | String | Quantity               |
| recurringState   | String | Subscription Status    |
| currency         | String | Currency               |
| country          | String | Country                |
| paymentId        | String | Payment ID             |
| price            | Float  | Price                  |
| iapVersion       | String | In-app Billing Version |
| playerId         | String | Player ID              |
| serverId         | String | Server ID              |
| level            | Int    | Level                  |
| userdata         | String | User Data              |
| metadata         | String | Metadata               |
| options          | String | Option                 |
| authCode         | String | Authentication Code    |

## Troubleshooting <a href="#undefined" id="undefined"></a>

Q. An error occurs on Android with the following message:

{% code overflow="wrap" %}

```
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.security.crypto.MasterKeys" on path: DexPathList[[zip file "/data/app/~~KKBtt9efgPjpqDSP6o3P1g==/com.nbase.je_beta-6fz3RrA1gqu27fSFW0ehcQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~KKBtt9efgPjpqDSP6o3P1g==/com.nbase.je_beta-6fz3RrA1gqu27fSFW0ehcQ==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
```

{% endcode %}

**A.** This error occurs because the `MasterKeys` class cannot be found. You need to add the following code to the `build.gradle` or `build.gradle.kts` file.

```
implementation("androidx.security:security-crypto:1.0.0")
```

Q. The following error occurs during Google login:

```
10: Developer console is not set up correctly.
```

**A.** You need to verify that the OAuth 2.0 Client ID and Client Secret of the web application registered in the Google Cloud Console are correctly entered in the GAMEPOT dashboard.

Q. The following error occurs during Google login:

```
16: Cannot find a matching credential.
```

**A.** This error can also occur if the package registered in the Google Cloud Console for OAuth 2.0 Android and the app's SHA-1 value do not match.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gamepot.io/basics/gamepot-3.0/images-and-media/editor/android-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
