3
votes

I am trying to integrate Google Sign In into my android app, but I got an error. When it ran an older version of Google Play services (for example 9.8.79) there was no problem, it worked perfectly. Then when it ran the latest version of Google Play services the problem appeared, the error code is

Status{statusCode=unknown status code: 12500, resolution=null

and I noticed the logcat message is :

 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

What could be the possible cause of this?

Thanks

the code is:

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'
}

project 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
}
2
Consider adding a snippet of your code - AndreyF
Ok @AndreyF ,I will do - Ives Shi
code:12500 indicates that there is nothing user can do to recover from the sign in failure. Switching to another account may or may not help. - Paresh P.
@Wizard yes,it it is a headache,but I must find the reason to make my project work。Alas! - Ives Shi
@Wizard It didn't work with another account,and the network is up,and when I used the older version of google play service it worked! - Ives Shi

2 Answers

1
votes

https://developers.google.com/identity/sign-in/android/sign-in follow this api documentation but keep in mind that inside WEB_CLIENT_ID use the value of client id which is generated inside google-services.json file.

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
votes

..first if you are getting error 12500, or 12502 and tried many times created new project and things are not working just calm down, just check your sha 1 and configuration, and most important if you added firebase services as well just keep one project for all and detete all other. make sure you added your sha1 to firebase console project setting also thats most important.

image fr clarification