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

1
2
3
4
5
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.0.1'
}
}

Host app module

  • build.gradle
1
apply plugin: 'com.google.gms.google-services'
  • 在app目录下放置一份google-services.json

Bundle google module

  • build.gradle
1
2
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控制台,否则报如下错误:

1
2
3
4
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依赖配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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

若编译报错:

1
No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version')

则在公共module中添加:

1
2
3
4
<resources>
<!-- Android-Sdk\extras\google\m2repository\com\google\android\gms\play-services -->
<integer name="google_play_services_version">12451000</integer>
</resources>

并在Bundle的AndroidManifest.xml中添加

1
<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 bundlestrings.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

1
<string name="server_client_id">587775597148-ui6j4bhthd378t6pj3rbeck337id6bdm.apps.googleusercontent.com</string>

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :