我正在尝试将Google登录集成到我的Android应用中,但是我收到了错误消息。当它运行旧版Google Play服务时(例如9.8.79)没有问题,它运行得很好。然后当它运行最新版本的Google Play服务时出现问题,错误代码为
Status{statusCode=unknown status code: 12500, resolution=null
我注意到logcat消息是:
12-21 16:47:57.128 909-1861/? W/ActivityManager: Unable to start service Intent { act=com.google.android.gms.signin.service.START pkg=com.google.android.gms } U=0: not found
12-21 16:47:57.129 909-2225/? W/ActivityManager: Unbind failed: could not find connection for android.os.BinderProxy@daa436e
12-21 16:47:57.129 10959-11128/? E/GmsClient: unable to connect to service: com.google.android.gms.signin.service.START on com.google.android.gms
12-21 16:47:57.133 909-1300/? I/ActivityManager: retrieveServiceLocked, callerApp: ProcessRecord{9210179 10959:com.google.android.gms.ui/u0a8}, flags: 400
12-21 16:47:57.134 909-1300/? W/ActivityManager: Unable to start service Intent { act=com.google.android.gms.signin.service.START pkg=com.google.android.gms } U=0: not found
12-21 16:47:57.134 909-1863/? W/ActivityManager: Unbind failed: could not find connection for android.os.BinderProxy@71e6a0f
12-21 16:47:57.135 10959-11128/? E/GmsClient: unable to connect to service: com.google.android.gms.signin.service.START on com.google.android.gms
可能的原因是什么?
由于
代码是:
private void googleSignIn() {
if(mGoogleApiClient == null){
GoogleSignInOptions gso = new GoogleSignInOptions
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestId()
.requestIdToken(getResources().getString(R.string.server_client_id))
.build();
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.enableAutoManage(this,this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.enableAutoManage(this, this)/* FragmentActivity *//* OnConnectionFailedListener */
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
if(mGoogleApiClient!=null){
mGoogleApiClient.connect();
}
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
app gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.qraved.imaginato.loginterminator"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.1.1'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-auth:9.6.1'
compile('com.twitter.sdk.android:twitter:2.1.1@aar') {
transitive = true;
}
compile 'com.facebook.android:facebook-android-sdk:4.28.0'
}
项目gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
答案 0 :(得分:0)
https://developers.google.com/identity/sign-in/android/sign-in请遵循此api文档,但请记住,在WEB_CLIENT_ID内部使用在google-services.json文件内部生成的客户端ID的值。
class MainActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFailedListener {
private val TAG = "JSAGoogleSignIn"
private val REQUEST_CODE_SIGN_IN = 1234
private val WEB_CLIENT_ID = "354298333018-XXXXXXXXXXXXXXXXX.apps.googleusercontent.com"
private var mAuth: FirebaseAuth? = null
private var mGoogleApiClient: GoogleApiClient? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var login_button = findViewById<Button>(R.id.button)
var txt_register = findViewById<TextView>(R.id.txt_register)
txt_register.setOnClickListener {
var intent = Intent(this@MainActivity, RegisterActivity::class.java)
finish()
startActivity(intent)
}
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(WEB_CLIENT_ID)
.requestEmail()
.build()
mGoogleApiClient = GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build()
mAuth = FirebaseAuth.getInstance()
sign_in_button.setOnClickListener {
val intent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient)
startActivityForResult(intent, REQUEST_CODE_SIGN_IN)
}
}
override fun onConnectionFailed(p0: ConnectionResult) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun updateUI(user: FirebaseUser?) {
if (user != null) {
Log.e("Email", "Value" + user.email)
}
}
override fun onStart() {
super.onStart()
val currentUser = mAuth!!.currentUser
updateUI(currentUser)
}
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == REQUEST_CODE_SIGN_IN) {
val result = Auth.GoogleSignInApi.getSignInResultFromIntent(data)
if (result.isSuccess) {
// successful -> authenticate with Firebase
val account = result.signInAccount
firebaseAuthWithGoogle(account!!)
} else {
// failed -> update UI
updateUI(null)
Toast.makeText(applicationContext, "SignIn: failed!" + result.status,
Toast.LENGTH_SHORT).show()
}
}
}
private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount) {
Log.e(TAG, "firebaseAuthWithGoogle():" + acct.id!!)
val credential = GoogleAuthProvider.getCredential(acct.idToken, null)
mAuth!!.signInWithCredential(credential)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success
Log.e(TAG, "signInWithCredential: Success!")
val user = mAuth!!.currentUser
updateUI(user)
} else {
// Sign in fails
Log.w(TAG, "signInWithCredential: Failed!", task.exception)
Toast.makeText(applicationContext, "Authentication failed!",
Toast.LENGTH_SHORT).show()
updateUI(null)
}
}
}
private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
try {
val account = completedTask.getResult(ApiException::class.java)
} catch (e: ApiException) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.e("TAG", "signInResult:failed code=" + e.statusCode)
}
}
答案 1 :(得分:-1)