I have a login Google sign-in login for Firebase made pretty much like this:
class LoginActivity : AppCompatActivity() {
private lateinit var binding: ActivityLoginBinding
private lateinit var signInButton: SignInButton
private lateinit var textView: TextView
private lateinit var signInClient: GoogleSignInClient
private val launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
// never comes here
textView.text = "Login result " + result.resultCode.toString()
}
else
textView.text = "Login result " + result.resultCode.toString()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding.root)
var gso: GoogleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build()
signInClient = GoogleSignIn.getClient(this, gso)
textView = binding.textView
signInButton = binding.signInButton
signInButton.setOnClickListener {
launcher.launch(signInClient.signInIntent)
}
}
}
It's been working fine on my main development computer, but I wanted to do some coding on another computer of mine too, so I copied the whole project to the other one. However, when I run the project on the second computer, it gets stuck by always getting RESULT_CANCELED when I click the sign-in button. What's going on?
I had the answer in my comment to Alex's comment, but didn't realize it. Copying the debug.keystore from my main development computer to the other one, wiping the emulator and restarting Android Studio did the trick. I think initially I didn't do the wipe which was causing me the issues.