Android
Garena guest accounts will be lost after uninstalling the game on Android devices. It is recommended that games encourage guest players to link their guest account to the platform account as soon as possible to avoid accidental loss of guest accounts and to enhance the social attributes of the game.
This article guides you through setting up Garena as an identity provider, enabling your Android game to access Player Network authentication services.
Prerequisites
1. Set up the Garena app
Contact the Garena team to activate the app and get the app ID and other related information.
For Player Network SDK V1.24 or later, also contact the Garena team to obtain the Garena_Username
and Garena_Password
for the Maven repository related to Garena SDK.
To use Garena's platform account linking, request Garena to enable APP_PLATFORM_BIND
.
- Create an account for Player Network Console.
- Create a new project for your game, or join an existing one.
- Download the SDK.
- Integrate the SDK.
- Add Garena as an authentication method for your project on Player Network Console.
Step 1: Configure the SDK
Open the project's INTLConfig.ini:
INTLConfig.ini[INTL environment]
# WARNING: You should change this URL to the production environment when you release your game.
INTL_URL = https://intlsdk-new-test.iegg.garena.com
GAME_ID = {INTL_GAME_ID}
SDK_KEY = {INTL_SDK_KEY}
[INTL Log]
LOG_LEVEL = 1
LOG_CONSOLE_OUTPUT_ENABLE = 1
LOG_FILE_OUTPUT_ENABLE = 1
LOG_ENCRYPT_ENABLE = 0
LOG_COMPRESS_ENABLE = 0
[Android LifeCycle]
LIFECYCLE = Garena
[Garena Channel Configurations]
GARENA_APP_SDK_ASSIGN_ID = {INTL_GARENA_APP_SDK_ASSIGN_ID}
GARENA_APP_SDK_KEY = {INTL_APP_KEY}- Set the Player Network SDK authentication domain to
INTL_URL = https://intlsdk-new-test.iegg.garena.com
, contact the Garena team for more details and to obtain the URL for the production environment. - Replace
{INTL_GAME_ID}
and{INTL_SDK_KEY}
with theGAME_ID
andSDK_KEY
assigned by Player Network Console. - Set
LOG_LEVEL = 1
,LOG_CONSOLE_OUTPUT_ENABLE = 1
,LOG_FILE_OUTPUT_ENABLE = 1
,LOG_ENCRYPT_ENABLE = 0
, andLOG_COMPRESS_ENABLE = 0
to output console logs and log files without encrypting or compressing the output. - Add Garena to
LIFECYCLE
. For more information, see SDK Environment. - Replace
{INTL_GARENA_APP_SDK_ASSIGN_ID}
with the registered Garena App ID. - Replace
{INTL_APP_KEY}
with the registered Garena App Key.
- Set the Player Network SDK authentication domain to
Define
manifestPlaceholders
in your gradle file by replacing{INTL_GARENA_APP_SDK_ASSIGN_ID}
,{INTL_FACEBOOK_APP_ID}
, and{INTL_GOOGLE_CLIENT_ID}
with the respective values of the app.- When integrating Player Network SDK V1.22 or later, also replace
{INTL_FACEBOOK_CLIENT_TOKEN}
with theFACEBOOK_CLIENT_TOKEN
. - When integrating Player Network SDK V1.24 or later, also replace
{INTL_GARENA_MAVEN_USERNAME}
and{INTL_GARENA_MAVEN_PASSWORD}
with theGarena_Username
andGarena_Password
respectively.
- Unity
- Unreal Engine
noteFor Unity 2022, edit
settingsTemplate.gradle
。For Unity 2019/2020/2021, edit
baseProjectTemplate.gradle
。For Unity 2018 and earlier, edit
mainTemplate.gradle
。android {
defaultConfig {
manifestPlaceholders = [
"GARENA_APP_ID":"{INTL_GARENA_APP_SDK_ASSIGN_ID}",
"FACEBOOK_APPID":"{INTL_FACEBOOK_APP_ID}",
"GOOGLE_CLIENT_ID":"{INTL_GOOGLE_CLIENT_KEY_ANDROID}",
"FACEBOOK_CLIENT_TOKEN":"{INTL_FACEBOOK_CLIENT_TOKEN}", // added in V1.22
"Garena_Username":"{INTL_GARENA_MAVEN_USERNAME}", // added in V1.24
"Garena_Password":"{INTL_GARENA_MAVEN_PASSWORD}", // added in V1.24
]
}
}noteFor Player Network SDK V1.17 or later, edit
INTLConfig_APL.xml
.For Player Network SDK V1.16.04 or earlier, edit
INTLCore_UPL.xml
.<buildGradleAdditions>
<insert>
<![CDATA[
android{
defaultConfig {
manifestPlaceholders += [
"GARENA_APP_ID":"{INTL_GARENA_APP_SDK_ASSIGN_ID}",
"FACEBOOK_APPID":"{INTL_FACEBOOK_APP_ID}",
"GOOGLE_CLIENT_ID":"{INTL_GOOGLE_CLIENT_KEY_ANDROID}",
"FACEBOOK_CLIENT_TOKEN":"{INTL_FACEBOOK_CLIENT_TOKEN}", // added in V1.22
"Garena_Username":"{INTL_GARENA_MAVEN_USERNAME}", // added in V1.24
"Garena_Password":"{INTL_GARENA_MAVEN_PASSWORD}", // added in V1.24
]
}
}]]>
</insert>
</buildGradleAdditions>- When integrating Player Network SDK V1.22 or later, also replace
Declare the permissions in the
AndroidManifest.xml
file according to the following code.cautionWRITE_EXTERNAL_STORAGE
is a sensitive permission.AndroidManifest.xml<manifest ... >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
...
</manifest>For Unreal Engine, update the Garena Billing Repository to 4.0.0 for Player Network SDK V1.13 and later
If Unreal Engine 4.25 is used,
- Download GooglePlayStoreHelper.java. Then replace the
{UE_PATH}/Engine/Plugins/Online/Android/OnlineSubsystemGooglePlay/Source/Java/com/epicgames/ue4/GooglePlayStoreHelper.java
file. - Download OnlineSubsystemGooglePlay_UPL.xml. Then replace the
{UE_PATH}/Engine/Plugins/Online/Android/OnlineSubsystemGooglePlay/Source/OnlineSubsystemGooglePlay_UPL.xml
file.
- Download GooglePlayStoreHelper.java. Then replace the
If Unreal Engine 4.26 or later is used,
- Download GooglePlayStoreHelper.java. Then replace the
{UE_PATH}/Engine/Plugins/Online/Android/OnlineSubsystemGooglePlay/Source/Java/BillingApiV2/com/epicgames/ue4/GooglePlayStoreHelper.java
file. - Modify the Billing Repository version in
{UE_PATH}/Engine/Plugins/Online/Android/OnlineSubsystemGooglePlay/Source/OnlineSubsystemGooglePlay_UPL.xml
to4.0.0
- Download GooglePlayStoreHelper.java. Then replace the
Step 2: Add Garena login
Add an observer to handle authentication callbacks.
- Unity
- Unreal Engine
// Add callbacks
public void AddAuthObserver()
{
INTLAPI.AddAuthResultObserver(OnAuthResultEvent);
}
// Remove callbacks
public void RemoveAuthObserver()
{
INTLAPI.RemoveAuthResultObserver(OnAuthResultEvent);
}
// Process the INTLAuthResult callback
public void OnAuthResultEvent(INTLAuthResult ret)
{
Debug.Log($"MethodID: {ret.MethodId}");
string methodTag = "";
if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_LOGIN)
{
methodTag = "Login";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_BIND)
{
methodTag = "Bind";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_AUTOLOGIN)
{
methodTag = "AutoLogin";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO)
{
methodTag = "QueryUserInfo";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT)
{
methodTag = "GetAuthResult";
}
}C++ Event Handling (above v1.15)
//configure callback
FINTLAuthEvent authEvent;
authEvent.AddUObject(this, &OnAuthResult_Implementation);
UINTLSDKAPI::SetAuthResultObserver(authEvent);
// Remove callbacks
UINTLSDKAPI::GetAuthResultObserver().Clear();void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Unreal Event Handling
void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Call the
AutoLogin
method.- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();
Call the
Login
method to ask for user input if auto-login fails.noteCurrently, the Player Network SDK supported Garena sub-channels on Android include
Guest
,Garena
,Facebook
, andGoogle
. To check the current sub-channel used to log in, check the sub-channel name returned in theExtraJson
field ofAuthResult
. For example,{"subChannel":"Facebook"}"
.Logging into the Facebook sub-channel of Garena:
- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.Garena, "", "{\"subChannel\":\"Facebook\"}");
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelGarena, "", "{\"subChannel\":\"Facebook\"}");
- If app is installed, open the app to log in, otherwise open a webpage to log in.
- Garena Login
permission
parameter differs from the rest of the channels. Users need to pass in the numeric in string format. For example, "2" or "4". The permissions are defined as follows:
Sync client authentication state with the game's backend and wait for the final authentication result.
Step 3: Test the login function
Search for the keyword "AuthResult" in the Player Network SDK logs to verify if the correct channel name and OpenID are returned. If they are, it indicates a successful configuration and the login function has been added successfully.
Link
Garena guest accounts will be lost after uninstalling the game on Android devices. It is recommended that games encourage guest players to link their guest account to the platform account as soon as possible to avoid accidental loss of guest accounts and to enhance the social attributes of the game.
Due to Garena's restrictions:
- If the Facebook login has been used before, it cannot be used as the sub-channel for the Garena login. Otherwise, error code
1013
is returned. - After linking the Garena account successfully, you cannot link it again.
When calling the Bind
interface, the App of the sub-channel (or a webpage) is opened to perform login authentication. Player Network SDK will link the account of the sub-channel with the guest account after a successful authentication.
- Unity
- Unreal Engine
// Log in as guest
INTLAPI.Login(INTLChannel.Garena, "", "{\"subChannel\":\"Guest\"}");
// Bind Logic
INTLAPI.Bind(INTLChannel.Garena, "", "{\"subChannel\":\"Facebook\"}");
// Log in as guest
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelGarena, "", "{\"subChannel\":\"Guest\"}");
// Bind Logic
UINTLSDKAPI::Bind(EINTLLoginChannel::kChannelGarena, "", "{\"subChannel\":\"Facebook\"}");
If linking a guest account to Garena fails, the game must call the guest login of Garena again.
After calling the Bind
interface, the session of Garena SDK is set to a new linked channel (with guest login state) no matter the result of the linking. If calling the Bind
interface again, the linking will fail because of session validation failure. Therefore, it is recommended to call the guest login again to return to the normal guest login state.
If you have trouble logging in through Garena, see Garena FAQs.