Atlas加载Google登录远程Bundle的配置及踩坑
Google开发文档:https://developers.google.com/identity/sign-in/android/sign-in
Google移动平台:https://firebase.google.com/
Google Service:https://developers.google.com/identity/sign-in/android/start
Google Play Service
准备工作: Install or update Google Play Service
豌豆荚搜索“谷歌安装器”,安装Google Service
基础服务
- Google 服务框架
- Google 账户管理程序
- Google Play 服务
- Google 日历同步服务
- Google 通讯录同步服务
商店服务
- Google Play 商店
Firebase途径
Android SDK 更新或升级 Google Play services
最新版本号为49
项目build.gradle
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.0.1'
}
}
Host app module
- build.gradle
apply plugin: 'com.google.gms.google-services'
- 在app目录下放置一份
google-services.json
Bundle google module
- build.gradle
compile 'com.google.firebase:firebase-core:16.0.3'
compile 'com.google.android.gms:play-services-auth:16.0.0'
- 在google目录下放置一份
google-services.json
注意:(1)在google目录下必须放置一份
google-services.json
,(2)在Firebase控制台添加SHA1证书指纹,(3)如果在Firebase上配置了最新信息,如SHA1证书指纹等,务必下载最新的google-services.json
,(4)巨坑:如果是在Firebase控制台创建应用,那么server_client_id应该填写网页应用的client_id,而不是Android客户端的client_id(一个网页应用对应多个Android应用,每添加一个SHA1证书指纹都会自动创建一个Android应用),(5)Firebase控制台开启电子邮件地址/密码登录:Authentication -> 登录方法 -> 启用"电子邮件地址/密码"、启用"Google",(6)巨坑:发布至Google Play的App会被重打包,签名也会被修改,在发布平台 -> 版本管理 -> 应用签名,可以看到Google Play为发布apk提供的签名值,需要将SHA1值添加至Firebase控制台,否则报如下错误:
com.google.android.gms.common.api.ApiException: 12500:
at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source)
at me.yezhou.lib.google.signin.GoogleSignActivity.onActivityResult(GoogleSignActivity.java:66)
Google Service途径
google bundle Gradle依赖配置
dependencies {
//Dependency for Google Sign-In
compile 'com.google.android.gms:play-services-auth:16.0.0'
//compile 'com.google.android.gms:play-services-appindexing:9.8.0'
//compile 'com.google.firebase:firebase-appindexing:16.0.1'
//Dependencies for the REST API example
compile('com.google.api-client:google-api-client:1.25.0', {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
})
compile('com.google.api-client:google-api-client-android:1.25.0', {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
})
compile('com.google.apis:google-api-services-people:v1-rev344-1.25.0', {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
})
}
google_play_services_version
若编译报错:
No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version')
则在公共module中添加:
<resources>
<!-- Android-Sdk\extras\google\m2repository\com\google\android\gms\play-services -->
<integer name="google_play_services_version">12451000</integer>
</resources>
并在Bundle的AndroidManifest.xml中添加
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
google_server_client_id
获取google_server_client_id
, 并在google bundle
的strings.xml
里面配置
配置地址:https://console.developers.google.com/projectselector/apis/credentials
OAuth 2.0 Client ID
-> Web client (auto created by Google Service)
-> 587775597148-ui6j4bhthd378t6pj3rbeck337id6bdm.apps.googleusercontent.com
<string name="server_client_id">587775597148-ui6j4bhthd378t6pj3rbeck337id6bdm.apps.googleusercontent.com</string>
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/18/atlas-load-google-login-remote-bundle-configuration/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论