Android SDK_安装SDK和配置环
安装GAMEPOT Android SDK后配置环境并关联GAMEPOT Dashboard和游戏,即可使用游戏开发所需的功能。
安装SDK
安装GAMEPOT Android SDK后,在Android Studio配置项目的方法如下。
请使用管理员账户登录Dashboard。
依次点击 SDK下载 > Android 菜单后,请点击 下载。
运行Android Studio后,请打开游戏项目。
解压已下载的AOS SDK文件后,请将libs文件夹内的所有文件复制到游戏项目的libs文件夹下。
修改build.gradle
修改 build.gradle文件的方法如下。
请使用下列代码修改项目root文件夹内的build.gradle文件。
buildscript { repositories { ... google() mavenCentral() maven { url "https://jitpack.io" } } dependencies { ... classpath 'com.google.gms:google-services:4.3.14' } } allprojects { repositories { ... google() mavenCentral() maven { url "https://jitpack.io" } } }
参考表格修改下列代码的值后,请使用代码修改app文件夹内的build.gradle文件。gamepot_payment值默认为空。
值
说明
gamepot_project_id
由GAMEPOT发放的项目ID (在Dashboard 项目设置 > 一般 菜单中进行确认)
gamepot_store
输入Store值
google
、one
或galaxy
gamepot_app_title
APP标题(FCM)
gamepot_push_default_channel
禁止更改(已注册的默认渠道名称)
facebook_app_id
由Facebook发放的APP ID
fb_login_protocol_scheme
fb[由Facebook发放的APP ID] ex) fb101010
facebook_client_token
Facebook控制台 > APP > 设置 > 高级设置 > 客户端Token
gamepot_elsa_projectid
使用NAVER Cloud ELSA服务时,输入ELSA项目ID (参阅Effective Log Search & Analytics)
gamepot_region
仅在GAMEPOT Dashboard创建地区为新加坡时输入sg
gamepot_license_url
仅在GAMEPOT Dashboard创建地区为日本时输入 https://gamepot.apigw.ntruss.com/fw/jp-v1
android { defaultConfig { ... // GamePot [START] resValue "string", "gamepot_project_id", "[projectId]" // required resValue "string", "gamepot_store", "[storeId]" // required resValue "string", "gamepot_payment", "[storeId]" // optional resValue "string", "gamepot_app_title","@string/app_name" // required (fcm) resValue "string", "gamepot_push_default_channel","Default" // required (fcm) resValue "string", "facebook_app_id", "[Facebook ID]" // facebook resValue "string", "fb_login_protocol_scheme", "fb[Facebook ID]" // (facebook) resValue "string", "facebook_client_token", "[Facebook客户端Token]" // Facebook控制台 > APP > 高级设置 > 客户端Token // resValue "string", "gamepot_elsa_projectid", "" // (ncp elsa) resValue "string", "gamepot_region", "" // Caution! Only if the gamepot region is Singapore , value as sg resValue "string", "gamepot_license_url", "" // Caution! Only if the gamepot region is Japan , value as https://gamepot.apigw.ntruss.com/fw/jp-v1 // GamePot [END] } packagingOptions { exclude 'META-INF/proguard/androidx-annotations.pro' } } repositories { flatDir { dirs 'libs' } } dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.multidex:multidex:2.0.1' // GamePot common [START] implementation(name: 'gamepot-common', ext: 'aar') implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } implementation('com.github.ihsanbal:LoggingInterceptor:3.0.0') { exclude group: 'org.json', module: 'json' } implementation "com.github.nisrulz:easydeviceinfo:2.4.1" implementation 'com.android.installreferrer:installreferrer:1.0' implementation 'com.google.code.gson:gson:2.8.2' implementation 'com.jakewharton.timber:timber:4.7.0' implementation 'com.squareup.okhttp3:okhttp:4.9.1' implementation 'com.apollographql.apollo:apollo-runtime:2.5.14' implementation 'com.apollographql.apollo:apollo-android-support:2.5.14' implementation 'com.android.billingclient:billing:7.0.0' implementation 'com.google.firebase:firebase-crashlytics-buildtools:2.9.1' implementation 'com.github.bumptech.glide:glide:3.7.0' implementation 'androidx.sqlite:sqlite-framework:2.0.1' implementation 'com.google.firebase:firebase-core:18.0.1' implementation 'com.google.firebase:firebase-messaging:23.1.2' implementation 'com.google.firebase:firebase-iid:21.1.0' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation 'pub.devrel:easypermissions:3.0.0' implementation(name: 'pageindicatorview-1.0.3', ext: 'aar') implementation(name: 'puree-4.1.6', ext: 'aar') implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' // GamePot common [END] implementation(name: 'gamepot-channel-base', ext: 'aar') // GamePot facebook [START] implementation(name: 'gamepot-channel-facebook', ext: 'aar') implementation 'com.facebook.android:facebook-android-sdk:14.1.1' // GamePot facebook [END] // GamePot google sigin [START] implementation(name: 'gamepot-channel-google-signin', ext: 'aar') implementation "com.google.android.gms:play-services-auth:19.0.0" // GamePot google sigin [END] } // ADD THIS AT THE BOTTOM apply plugin: 'com.google.gms.google-services'
请将自Google Developer Center获取的google-service.json文件复制到app文件夹下。
请刷新Android Studio。
刷新失败时
若尝试刷新时显示通知消息后失败,请按以下方式解决相应问题。
消息: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018.
For more information see: Add build dependencies | Android Studio | Android Developers 说明:由于不再支持
compile
设置,因此请将已输入至项目代码的compile
部分修改为implementation
。
消息:No matching client found for package name '[packagename]' 说明:请将APP的包名称和在google-service.json文件声明的包名称改为一致。
设置AndroidManifest.xml
若要通过设置AndroidManifest.xml添加一般游戏使用的设置值,请使用下列代码。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!--设置为没有通话功能的设备(平板电脑等)也能从商店进行下载-->
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<!--设置为没有麦克风的设备也能从商店下载支持语音聊天的游戏-->
<uses-feature android:name="android.hardware.microphone" android:required="false" />
<!--allowBackup必须设置为false。若设置为false,重新安装游戏时不会自动恢复shared preference值。-->
<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:replace="android:allowBackup">
<!--resizeableActivity: 禁用应用分屏查看功能-->
<activity
android:resizeableActivity="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--与Galaxy S8屏幕对应-->
<meta-data android:name="android.max_aspect" android:value="2.1" />
</application>
</manifest>
设置推送通知图标
可设置接收推送消息时要显示于通知栏的图标。若不额外设置,则使用包含在SDK的默认图片,也可自行设置匹配游戏的图标。若使用Android Asset Studio{target="_blank"},将自动为各文件夹制作图像,非常便利。
设置推送通知图标的方法如下。
按照以下方法在项目路径下分别创建res/drawable文件夹后,请根据各文件夹大小添加图像文件。
文件夹名称
大小
res/drawable-mdpi/
24x24
res/drawable-hdpi/
36x36
res/drawable-xhdpi/
48x48
res/drawable-xxhdpi/
72x72
res/drawable-xxxhdpi/
96x96
请将图像文件名改为ic_stat_gamepot_small。
初始化
若要进行初始化,请在MainActivity.java文件使用下列代码。
import io.gamepot.common.GamePot;
import io.gamepot.common.GamePotLocale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 初始化GAMEPOT。请务必在context输入application context。
// 请在调用其他API前,首先调用setup API。
GamePot.getInstance().setup(getApplicationContext());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
GamePot.getInstance().onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onStart() {
super.onStart();
GamePotChat.getInstance().start();
GamePot.getInstance().onStart(this);
}
@Override
protected void onStop() {
super.onStop();
GamePotChat.getInstance().stop();
}
@Override
protected void onDestroy() {
super.onDestroy();
GamePot.getInstance().onDestroy();
}
Last updated