Commit 7eb853ba24782a5b378be6dccb4e80a9f0001481

Authored by 赵康
1 parent 998c3827ad
Exists in master

增加混淆配置

Showing 2 changed files with 7 additions and 3 deletions Inline Diff

1 # Gump SDK 5 for Android接入文档 1 # Gump SDK 5 for Android接入文档
2 2
3 V5 3 V5
4 2019年08月01日 4 2019年08月06日
5 5
6 ## 版本概述 6 ## 版本概述
7 7
8 此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入. 8 此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入.
9 9
10 此SDK适用android4.0以上系统. 10 此SDK适用android4.0以上系统.
11 11
12 本SDK分为两个部分:登录和支付,请按需引用依赖包. 12 本SDK分为两个部分:登录和支付,请按需引用依赖包.
13 13
14 ## 第一章 接入指南 14 ## 第一章 接入指南
15 ### 1.依赖导入 15 ### 1.依赖导入
16 配置gradle,以下为必须项 16 配置gradle,以下为必须项
17 17
18 repositories{ 18 repositories{
19 maven{ 19 maven{
20 url "http://117.50.8.198:8081/nexus/content/repositories/sdk" 20 url "http://117.50.8.198:8081/nexus/content/repositories/sdk"
21 } 21 }
22 } 22 }
23 dependencies { 23 dependencies {
24 //登录功能依赖 24 //登录功能依赖
25 implementation 'com.gump:Passport:5.2.2' 25 implementation 'com.gump:Passport:5.2.3'
26 //支付功能依赖 26 //支付功能依赖
27 implementation 'com.gump:Payment:5.2.5' 27 implementation 'com.gump:Payment:5.2.5'
28 } 28 }
29 29
30 ### 2.修改AndroidManifest.xml文件 30 ### 2.修改AndroidManifest.xml文件
31 首先添加必要的权限,如下所示: 31 首先添加必要的权限,如下所示:
32 32
33 <uses-permission android:name="android.permission.INTERNET" /> 33 <uses-permission android:name="android.permission.INTERNET" />
34 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 34 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
35 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 35 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
36 <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> 36 <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. -->
37 <uses-permission android:name="com.android.vending.BILLING" /> 37 <uses-permission android:name="com.android.vending.BILLING" />
38 38
39 创建一个strings 配置如下 39 创建一个strings 配置如下
40 40
41 <string name="app_id">your_play_games_app_id</string> 41 <string name="app_id">your_play_games_app_id</string>
42 42
43 增加play games的meta-data配置 43 增加play games的meta-data配置
44 44
45 <meta-data 45 <meta-data
46 android:name="com.google.android.gms.games.APP_ID" 46 android:name="com.google.android.gms.games.APP_ID"
47 android:value="@string/app_id"/> 47 android:value="@string/app_id"/>
48 <meta-data 48 <meta-data
49 android:name="com.google.android.gms.version" 49 android:name="com.google.android.gms.version"
50 android:value="@integer/google_play_services_version"/> 50 android:value="@integer/google_play_services_version"/>
51 51
52 ### 3.1 初始化与配置 52 ### 3.1 初始化与配置
53 53
54 *若要使用V4版支付请设置 54 *若要使用V4版支付请设置
55 55
56 SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4); 56 SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4);
57 57
58 *执行初始化 58 *执行初始化
59 59
60 SDKAgent.init(Context,Appid,ChannelId); 60 SDKAgent.init(Context,Appid,ChannelId);
61 61
62 ### 3.2 登录接入 62 ### 3.2 登录接入
63 AndroidManifest.xml配置: 63 AndroidManifest.xml配置:
64 64
65 <activity 65 <activity
66 android:name="com.gump.gpassport.GumpLoginActivity" 66 android:name="com.gump.gpassport.GumpLoginActivity"
67 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" 67 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
68 android:launchMode="singleTask" 68 android:launchMode="singleTask"
69 android:screenOrientation="behind" 69 android:screenOrientation="behind"
70 android:theme="@style/Theme.AppCompat.Light.NoActionBar"/> 70 android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
71 构建Passport实例 71 构建Passport实例
72 72
73 passport = new Passport.Builder().context(Context).setListener(StateListener).build(); 73 passport = new Passport.Builder().context(Context).setListener(StateListener).build();
74 74
75 其中StateListener为登录状态监听接口,需要实现如下方法 75 其中StateListener为登录状态监听接口,需要实现如下方法
76 76
77 //成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象 77 //成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象
78 void onActionSucced(Actions action, GamePlayer player) 78 void onActionSucced(Actions action, GamePlayer player)
79 //失败回调 79 //失败回调
80 void onActionFailured() 80 void onActionFailured()
81 81
82 Actinos枚举: 82 Actinos枚举:
83 83
84 SIGN 登录 84 SIGN 登录
85 SWITCH_PENDING 切换PlayGame账号,需重启游戏 85 SWITCH_PENDING 切换PlayGame账号,需重启游戏
86 SWITCH 已切换甘普账号,需重新加载用户角色信息 86 SWITCH 已切换甘普账号,需重新加载用户角色信息
87 调用登录 87 调用登录
88 88
89 passport.signIn(Activity); 89 passport.signIn(Activity);
90 90
91 接下来,添加生命周期处理方法 91 接下来,添加生命周期处理方法
92 92
93 @Override 93 @Override
94 protected void onResume() { 94 protected void onResume() {
95 super.onResume(); 95 super.onResume();
96 passport.onResume(); 96 passport.onResume();
97 } 97 }
98 98
99 处理结果返回 99 处理结果返回
100 100
101 @Override 101 @Override
102 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 102 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
103 if (!passport.onActivityResult(requestCode, resultCode, data)) 103 if (!passport.onActivityResult(requestCode, resultCode, data))
104 super.onActivityResult(requestCode, resultCode, data); 104 super.onActivityResult(requestCode, resultCode, data);
105 } 105 }
106 106
107 ### 3.3 账号联动 107 ### 3.3 账号联动
108 108
109 passport.link(Activity); 109 passport.link(Activity);
110 110
111 ### 3.4 账号切换 111 ### 3.4 账号切换
112 切换到PlayGame账号 112 切换到PlayGame账号
113 113
114 passport.switchAccount(); 114 passport.switchAccount();
115 115
116 116
117 ### 3.5 支付接入 117 ### 3.5 支付接入
118 注册相应的Activity,具体如下: 118 注册相应的Activity,具体如下:
119 119
120 <activity 120 <activity
121 android:name="com.gump.payment.PaymentActivity" 121 android:name="com.gump.payment.PaymentActivity"
122 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" 122 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
123 android:screenOrientation="behind" 123 android:screenOrientation="behind"
124 android:launchMode="singleTask" 124 android:launchMode="singleTask"
125 android:theme="@style/Theme.Translucent"> 125 android:theme="@style/Theme.Translucent">
126 <intent-filter> 126 <intent-filter>
127 <action android:name="android.intent.action.VIEW"/> 127 <action android:name="android.intent.action.VIEW"/>
128 128
129 <category android:name="android.intent.category.DEFAULT"/> 129 <category android:name="android.intent.category.DEFAULT"/>
130 130
131 <category android:name="android.intent.category.BROWSABLE"/> 131 <category android:name="android.intent.category.BROWSABLE"/>
132 132
133 <data 133 <data
134 android:host="com.gump.sdk" 134 android:host="com.gump.sdk"
135 android:scheme="gump+游戏的appId"/> 135 android:scheme="gump+游戏的appId"/>
136 </intent-filter> 136 </intent-filter>
137 </activity> 137 </activity>
138 138
139 139
140 1)判断是否使用三方支付 140 1)判断是否使用三方支付
141 141
142 Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() { 142 Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() {
143 @Override 143 @Override
144 public void onResult(boolean isRisk) { 144 public void onResult(boolean isRisk) {
145 //isRisk==true时使用IAB支付,isRisk==false时使用三方支付 145 //isRisk==true时使用IAB支付,isRisk==false时使用三方支付
146 } 146 }
147 }); 147 });
148 148
149 2)三方支付调用 149 2)三方支付调用
150 150
151 Bundle payInfo = new Bundle(); 151 Bundle payInfo = new Bundle();
152 payInfo.putString("product", "wa2"); 152 payInfo.putString("product", "wa2");
153 payInfo.putFloat("amount", 0.1f); 153 payInfo.putFloat("amount", 0.1f);
154 payInfo.putString("extraInfo", "This is demo!"); 154 payInfo.putString("extraInfo", "This is demo!");
155 payInfo.putString("serverId", "100"); 155 payInfo.putString("serverId", "100");
156 payInfo.putString("roleId", "41080"); 156 payInfo.putString("roleId", "41080");
157 Payment.pay(Activity, payInfo, PurchaseCallback); 157 Payment.pay(Activity, payInfo, PurchaseCallback);
158 158
159 3)Google IAB支付调用 159 3)Google IAB支付调用
160 160
161 Bundle payInfo = new Bundle(); 161 Bundle payInfo = new Bundle();
162 payInfo.putString("product", "180010"); 162 payInfo.putString("product", "180010");
163 payInfo.putFloat("amount", 0.1f); 163 payInfo.putFloat("amount", 0.1f);
164 payInfo.putString("extraInfo", "This is demo!"); 164 payInfo.putString("extraInfo", "This is demo!");
165 payInfo.putString("serverId", "100"); 165 payInfo.putString("serverId", "100");
166 payInfo.putString("roleId", "41080"); 166 payInfo.putString("roleId", "41080");
167 Payment.launchIAP(Activity, payInfo, PurchaseCallback); 167 Payment.launchIAP(Activity, payInfo, PurchaseCallback);
168 168
169 PurchaseCallback为支付状态回调接口,此接口含有3个方法 169 PurchaseCallback为支付状态回调接口,此接口含有3个方法
170 170
171 @Override 171 @Override
172 public void onPurchaseCompleted(PurchaseResult result) { 172 public void onPurchaseCompleted(PurchaseResult result) {
173 Log.i(TAG,"purchase completed"); 173 Log.i(TAG,"purchase completed");
174 } 174 }
175 175
176 @Override 176 @Override
177 public void onPurchaseError(int code, String msg) { 177 public void onPurchaseError(int code, String msg) {
178 Log.i(TAG,"purchase error"); 178 Log.i(TAG,"purchase error");
179 } 179 }
180 180
181 @Override 181 @Override
182 public void onPurchaseCanceled() { 182 public void onPurchaseCanceled() {
183 Log.i(TAG,"purchase canceled"); 183 Log.i(TAG,"purchase canceled");
184 } 184 }
185 185
186 ## 第二章 常见问题 186 ## 第二章 常见问题
187 ### 问题1: 如何避免混淆对SDK的影响? 187 ### 问题1: 如何避免混淆对SDK的影响?
188 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java 188 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java
189 类,导致SDK无法正常工作,解决方法如下: 189 类,导致SDK无法正常工作,解决方法如下:
190 Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 190 Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上
191 191
192 -keep class com.gump.payment.web.* {*;} 192 -keep class com.gump.payment.web.* {*;}
193 -keepclassmembers class com.gump.gpassport.LinkHandler{
194 public <methods>;
195 }
196 -keepclassmembers class com.gump.gpassport.LinkHandler$Result{*;}
193 197
194 使得混淆的时候不会影响SDK的命名空间。 198 使得混淆的时候不会影响SDK的命名空间。
1 apply plugin: 'com.android.application' 1 apply plugin: 'com.android.application'
2 2
3 3
4 android { 4 android {
5 compileSdkVersion 27 5 compileSdkVersion 27
6 defaultConfig { 6 defaultConfig {
7 applicationId "com.gump.passport.demo" 7 applicationId "com.gump.passport.demo"
8 minSdkVersion 15 8 minSdkVersion 15
9 targetSdkVersion 27 9 targetSdkVersion 27
10 versionCode 9 10 versionCode 9
11 versionName "1.0.9" 11 versionName "1.0.9"
12 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 vectorDrawables.useSupportLibrary = true 13 vectorDrawables.useSupportLibrary = true
14 } 14 }
15 buildTypes { 15 buildTypes {
16 release { 16 release {
17 minifyEnabled false 17 minifyEnabled false
18 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 } 19 }
20 } 20 }
21 21
22 applicationVariants.all { 22 applicationVariants.all {
23 variant -> 23 variant ->
24 variant.outputs.all { 24 variant.outputs.all {
25 outputFileName = "SDKDemo-" + variant.name + defaultConfig.versionName + ".apk" 25 outputFileName = "SDKDemo-" + variant.name + defaultConfig.versionName + ".apk"
26 } 26 }
27 } 27 }
28 28
29 lintOptions { 29 lintOptions {
30 abortOnError false 30 abortOnError false
31 } 31 }
32 } 32 }
33 33
34 dependencies { 34 dependencies {
35 implementation fileTree(dir: 'libs', include: ['*.jar']) 35 implementation fileTree(dir: 'libs', include: ['*.jar'])
36 implementation 'com.android.support:appcompat-v7:27.1.1' 36 implementation 'com.android.support:appcompat-v7:27.1.1'
37 implementation 'com.android.support:support-v4:27.1.1' 37 implementation 'com.android.support:support-v4:27.1.1'
38 implementation 'com.android.support:support-vector-drawable:27.1.1' 38 implementation 'com.android.support:support-vector-drawable:27.1.1'
39 testImplementation 'junit:junit:4.12' 39 testImplementation 'junit:junit:4.12'
40 40
41 //基础功能依赖,必须 41 //基础功能依赖,必须
42 // implementation 'com.gump:base:5.1.1' 42 // implementation 'com.gump:base:5.1.1'
43 // implementation project(':base') 43 // implementation project(':base')
44 // 登录功能依赖 44 // 登录功能依赖
45 implementation 'com.gump:Passport:5.2.2' 45 implementation 'com.gump:Passport:5.2.3'
46 // implementation project(':passport') 46 // implementation project(':passport')
47 //支付功能依赖 47 //支付功能依赖
48 implementation 'com.gump:Payment:5.2.5' 48 implementation 'com.gump:Payment:5.2.5'
49 // implementation project(':payment') 49 // implementation project(':payment')
50 } 50 }
51 51