# Cocos2d-x

## Quick Start

Download the Latest Version

{% embed url="<https://github.com/naver/navergame-sdk-cocos2dx/releases/tag/1.3.7>" %}

## Application of Navergame SDK to the Pre-existing Project

This guideline has been written in respect to version 3.17.2 of Cocos2d-x.

### 1. Plugin Configuration

* The files needed for the SDK are contained in the Plugins folder within the sample project.

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJ4w95Cr7TmTcybKyS%2F-McJ5cJSTCZUwb5mhcnB%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%206.14.57.png?alt=media\&token=1076362b-ebb2-43a1-ae3e-3f2734271e1a)

1. )  android : Contains the files needed for the android build.&#x20;
2. ) ios : Contains the files needed for the ios build.&#x20;
3. ) navergamesdk : contains the cocos2d-x project as well as the files that have to be connected to the respective platforms, such as android and ios.

### 2. Plugin Installation

* In order to synchronize the SDK with your company’s Cocos2d-x project, copy the **navergamesdk folder** within **Plugins into the Classes folder within your company’s project.**

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McIrj8aJIYh0xUh06zP%2F-McIuDtoV5hCqJHjgHJ5%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%205.20.32.png?alt=media\&token=7403cae2-a14f-475d-a11b-58673217b6c1)

* If your company is **planning to release on a single platform, either android or ios**, from the project, **keep only the relevant folder**, android or ios, located at the bottom end of the platform and delete the rest.

#### 2-1. NaverGameSDK.h

* &#x20;The file contains the written code necessary for the sdk connection.

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McIv6xS30r2GAz88uUS%2F-McIyKV-MAF-itbH87wv%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%205.38.46.png?alt=media\&token=74372edd-4463-460d-bd31-dca9ffc52197)

### 3. Plugin Application

Include the header file in the location within your company’s project that is trying to use the sdk. (Applied to HelloWorldScene.h for the sample project)

```
#include "NaverGameSDK.h"�
```

* If it is unable to find NaverGameSDK.h, the header file has to also be included in the rootProject/CmakeLists.txt as shown in the image below.

![Register the header file and the cpp file.](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJ7gXmyyaPp70dt4Jn%2F-McJARfAGf6V0QpPCVLf%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%206.35.45.png?alt=media\&token=fb6e5db5-b906-447b-b52f-f7eddecc63b5)

![Register the navergamesdk folder.](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJQpF8rM81D1VeljCP%2F-McJhgkD4XHZE5jeRjCx%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%209.05.30.png?alt=media\&token=fca7fb67-f21d-4d77-9c72-1498ef04c297)

#### 3-1. NaverGame SDK initialization

During the initializing of Navergame SDK, the options have to be set as shown in the following, and the init() method has to be called.&#x20;

* ClientId: The Client Id received after registering the application at [developers center](https://developers.naver.com/main/) upon logging in with a Naver Id.&#x20;
* ClientSecret: The client secret received after registering the application at [developers center](https://developers.naver.com/main/) upon logging in with a Naver Id.
* LoungeId: The Lounge Id received after requesting for an official lounge.

####

```
nng::NaverGameSDK::init("UKvNABLDsyEJusJGsXL2", "rK4suc_Qd0", "naver_game_4developer");
```

#### 3-2. SDK Event Listener Registration

In order to receive the various events sent from the SDK, a listener has to be registered.

```
//리스너는 NaverGameSDK.h 에 선언되어있습니다.
nng::NaverGameSDK::setSdkListener(this);
```

#### �3-3. A Look into SDK Support Function

1. Restoring home banner

   ```
   nng::NaverGameSDK::startHomeBanner();
   ```
2. Restoring maintenance banner

   ```
   nng::NaverGameSDK::startSorryBanner();�
   ```
3. Restoring specific bulletin board

   ```
   nng::NaverGameSDK::startBoard(boardId);
   ```
4. �Restoring specific post

   A method that immediately runs with the number of the registered post. Under the case of a **scheduled notification post that have scheduled through scheduled exposure**, the number of the scheduled post must be inputted into FeedId and IsTempFeedId must be inputted as **True**.

   ```
   nng::NaverGameSDK::startFeed(feedId, isTempFeedId);
   ```
5. �Terminating sdk

   ```
   nng::NaverGameSDK::stopSdk
   ```
6. Restoring country codes

   Obtain the countryCode of the mobile device. It must be called for **after the init() method is called** in order to obtain the normal value.

   ```
   nng::NaverGameSDK::getCountryCode();
   ```

   The countryCode is the country code ([ISO 3166-1 alpha-2](https://ko.wikipedia.org/wiki/ISO_3166-1_alpha-2)) composed of two alphabets. This enables branch processing by countries within the codes. The notable country codes are as shown in the following. Refer to the[ link ](https://ko.wikipedia.org/wiki/ISO_3166-1_alpha-2)for other country codes.

   | Country Code | Country                  |
   | ------------ | ------------------------ |
   | CN           | China                    |
   | JP           | Japan                    |
   | KR           | Republic of Korea        |
   | TH           | Thailand                 |
   | US           | United States of America |

## Application of the Navergame SDK to the Android Project

The following is the android build environment for the sample project. Please use it as a reference.

* Cocos2d-x **3.17.2**
* Android Studio **4.2**
* Gradle **4.9 (proj.android/gradle/wrapper/gradle-wrapper.properties)**
* Ndk **16.1.4479499**
* Cmake **3.10.2.4988404 (**&#x77;ith Ninja **1.10.2)**

###

### 1. Add the bridge file (code) that connects Cocos2d-x and Android.

**The Plugins folder within the sample project**

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJ4w95Cr7TmTcybKyS%2F-McJ5cJSTCZUwb5mhcnB%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%206.14.57.png?alt=media\&token=1076362b-ebb2-43a1-ae3e-3f2734271e1a)

The **android** folder content of the **Plugins** folder

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJAoI8RZjl939K-Cyl%2F-McJDsNy1Cfdw8XtfXZt%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%206.51.00.png?alt=media\&token=2ed80099-b8a4-4674-8f15-30db88b190f6)

1. ) com... Near the end of the folder is the **NNGSdk.java file** that serves as the bridge between android and cocos projects.&#x20;
2. ) navergame-sdk-gradle-x.x.x.aar is a **Navergame sdk library.**

**This is the directory structure of the sample project.**

<div align="center"><img src="https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJAoI8RZjl939K-Cyl%2F-McJMcStby7viqgww_FR%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%207.29.17.png?alt=media&#x26;token=1809e197-5af5-4eb5-ae42-1fb7ac2ba7bf" alt=""></div>

#### 1-1. navergame-sdk-gradle-x.x.x.aar

This is the Naver Game SDK library.

* Paste into the rootProject/proj.android/app/libs folder. If a libs folder is not present, create one.

#### 1-2. NNGSdk.java

The file that has the bridge code that connects Cocos2d-x project and SDK from Android.

* Paste into the rootProject/proj.android/app/src folder. Paste the entire folder that starts with com..

#### 1-3. NaverGameSDK.cpp

The file that has the bridge code that connects the Android project and Cocos2d-x.

* Check if the rootProject/Classes/navergamesdk/platform/android/NaverGameSDK.cpp file is present, and if not, find and paste it from the Plugins folder.&#x20;
* Depending on the version of cocos2d-x, the JniHelper might be written in a different name, so if the version is different, check.

```
#include "NaverGameSDK.h"
#include "platform/android/jni/JniHelper.h"

using namespace cocos2d;

namespace nng {
    static bool getStaticMethod(JniMethodInfo &methodinfo, const char *methodName, const char *paramCode) {
        static const char* kCafeSdkClass = "com/navercorp/nng/cocos2dx/sample/NNGSdk";
        return JniHelper::getStaticMethodInfo(methodinfo, kCafeSdkClass, methodName, paramCode);
    }

    static NaverGameSDKListener* sdkListener = nullptr;

    void NaverGameSDK::setSdkListener(NaverGameSDKListener* listener) {
        sdkListener = listener;
    }

    void NaverGameSDK::init(std::string clientId, std::string clientSecret, std::string loungeId) {
        JniMethodInfo t;
        if (getStaticMethod(t, "init","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) {
            jstring _clientId = t.env->NewStringUTF(clientId.c_str());
            jstring _clientSecret = t.env->NewStringUTF(clientSecret.c_str());
            jstring _loungeId = t.env->NewStringUTF(loungeId.c_str());

            t.env->CallStaticVoidMethod(t.classID, t.methodID, _clientId, _clientSecret, _loungeId);

            t.env->DeleteLocalRef(_clientId);
            t.env->DeleteLocalRef(_clientSecret);
            t.env->DeleteLocalRef(_loungeId);
            t.env->DeleteLocalRef(t.classID);
        }
    }

    .
    .
    .

    extern "C" {
        JNIEXPORT void JNICALL
        Java_com_navercorp_nng_cocos2dx_sample_NNGSdk_onSdkStarted(JNIEnv* env, jclass thiz) {
            if (sdkListener == nullptr) return;
            sdkListener->onSdkStarted();
        }

        .
        .
        .
    }
}   /* namespace nng */
```

* kCafeSdkClass = "**com/navercorp/nng/cocos2dx/sample/NNGSdk**";

  * This is the location path of the NNGSdk.java file. If the location path of the NNGSdk.java had been changed, make adjustments according to the relevant location.

* Java\_**com\_navercorp\_nng\_cocos2dx\_sample\_NNGSdk**\_~~Funtion네임~~
  * The is the location path of the NNGSDK.java file. If the location path of the NNGSdk.java had been changed, make adjustments according to the relevant location.

###

### 2. Settings Required to Build to Android

#### 1-1. AndroidManifest.xml

* Add the necessary permissions from the SDK to the rootProject/proj.android/app/AndroidManifest.xml file.

```markup
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
```

#### 1-2. build.gradle

* Add the SDK and the library needed for the SDK to the rootProject/proj.android/app/build.gradle file.

```
dependencies {
    implementation project(':libcocos2dx')
    /**
     * Navergame sdk와 필요한 libraries
     */
    implementation files('libs/navergame-sdk-gradle-1.1.0.aar')
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.72"            // Kotlin
    implementation "androidx.viewpager2:viewpager2:1.0.0"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
    implementation "com.github.bumptech.glide:glide:3.7.0"                // Glide
    implementation "com.squareup.retrofit2:retrofit:2.6.4"                // Retrofit, Gson
    implementation "com.squareup.retrofit2:converter-gson:2.6.4"          // Retrofit, Gson
}
```

#### 1-3. ndk and cmake installation

* Instructions for using Android Studio
  * Android Studio -> Preferences -> Search sdk using the search function, and download the ndk and the cmake from the sdk tools tab. (Check Show Package Details.)

![With respect to the version cocos-3.17.2, versions ndk-16.1.4479499 and cmake-3.10.2.4988404 were used.](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJnpN3L2H0Uo9vBFb7%2F-McJseKJSkVdlkuDQb6w%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%209.52.00.png?alt=media\&token=06aa45bc-0243-4aa3-8d88-454445766cbf)

#### **1-4.** ndk, cmake application

* Input the ndk and cmake file installation path to the rootProject/proj.android/local.properties file.

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJnpN3L2H0Uo9vBFb7%2F-McJtj1LMQZwnn2HC9O1%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%209.58.21.png?alt=media\&token=dbde3195-22d0-447f-97cc-45f3f622aed3)

###

### 3. Building with Android

**There are two build methods** for Cocos2d-x project with Android.

* cmake
* ndk

The exact naming may differ with respect to the version of cocos2d-x, so please check. Using version 3.17.2, it can be checked in the build.gradle file.

![In the case of version 3.17.2, it is referred to as 'ndk-build' and 'cmake.’](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJk2TjCGDSa2x1ttXo%2F-McJlLgr6spgvYqlwSlt%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%209.21.41.png?alt=media\&token=4cdbcfe2-9cef-4006-a573-8c27c3a060ad)

#### 3-0. Build Type Application Method

Can be determined from the **PROP\_BUILD\_TYPE** property within the rootProject/proj.android/gradle.properties file.

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJk2TjCGDSa2x1ttXo%2F-McJn169Oaajo1uZGilJ%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%209.29.08.png?alt=media\&token=d3143e57-3f5c-4e9d-9208-524c34fa9b79)

* If wanting to build with cmake, set **PROP\_BUILD\_TYPE=cmake**.

#### 3-1. Building with CMAKE

* Check **PROP\_BUILD\_TYPE=cmake** within rootProject/proj.android/gradle.properties.
* [Check if the necessary file and folder paths necessary for the SDK have been added to the](https://app.gitbook.com/@navergame/s/naver-game/integration-guide/cocos2d-x#3) rootProject/CmakeList.txt.
* Check if the file installation path for the cmake and the ndk have been inputted properly to rootProject/proj.andorid/local.properties.
* Ninja is needed for the cmake build. Check the installation status of ninja.
* Click the build button!

�

#### **3-2.** Building with NDK

* Check **PROP\_BUILD\_TYPE=ndk-build** within rootProject/proj.android/gradle.properties.
* Add the **files and folder paths necessary for the SDK** within rootProject/proj.android/app/jni/Android.mk.

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-McJvqjWnDOkrtL2gB1X%2F-McJwtGAkvcoXaIiCTkq%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-06-16%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%2010.12.12.png?alt=media\&token=de47e69f-ccba-44a2-8f28-dbf345da0377)

* Check if the ndk file installation path has been properly inputted into rootProject/proj.andorid/local.properties.
* Click the build button!

## Application of Navergame SDK to iOS Projects

{% hint style="info" %}
Naver Game iOS SDK supports iOS versions 12.0 and above.
{% endhint %}

Set the development environment as shown in the following in XCode in order to use NaverGame SDK.

* Select the app that is going to be run amongst the **TARGETS** category.&#x20;
* Select the **Build Setting tab** and find **Other Linker Flags** from the **Linking** category.&#x20;
  * If in either **Basic** or **Customized** modes, the **Other Linker Flag** might not appear, and in this case select **All** mode.
  * It can be easily found by entering **Other Linker Flag** into the search bar located in the upper right corner.
* Add the **-ObjC** option and the **-lc++** option to **Other Linker Flags**.

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-MVVeeTzDqBJfR2HH_Pw%2F-MVVfw0vZl_D1l5orL39%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-03-11%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%206.46.59.png?alt=media\&token=d1af769c-b34c-4256-9bfb-6a463f6f2670)

* Add the following option to obtain user permission to **Info.plist**.
  * Privacy - Camera Usage Description
  * Privacy - Photo Library Usage Description

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-MW35z3aXWRAv8pcUdjp%2F-MW36ZfA0NvJ6u1xfQwa%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-03-18%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%203.55.04.png?alt=media\&token=3e7606d6-b86d-4322-83e3-f53e6afd57c4)

* Select the app that is going to be run amongst the **TARGETS** category, and input the Identifier values and **URL Schemes values** into the **URL Types** category of the **Info** tab.&#x20;
* The **Identifier value** can be checked from the **General** tab of the relevant **TARGET**.&#x20;
* For the **URL Schemes value** , input the URL Scheme value that was used to register for the application in the [developers center](https://developers.naver.com/main/) after logging in with a Naver Id.

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-MVnzyQPox2s4-fhYFqa%2F-MVo-tflgFD1-pKeLbUt%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-03-15%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%2012.49.14.png?alt=media\&token=cfffd69d-d2ba-4370-b271-ba2b0afe5eb4)

![](https://1404903084-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MU6QuWI7G-kd5t_nYbd%2F-MVnzyQPox2s4-fhYFqa%2F-MVo-x3cQ5EyiTLK4kra%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-03-15%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%2012.45.30.png?alt=media\&token=f7a15389-80a1-4bcc-b888-d5ade97b4d59)
