facebook-android-sdk
facebook-android-sdk copied to clipboard
Cannot login using CustomTab with androidx.activity 1.5.1.
Checklist before submitting a bug report
- [X] I've updated to the latest released version of the SDK
- [X] I've searched for existing Github issues
- [X] I've looked for existing answers on Stack Overflow, the Facebook Developer Community Forum and the Facebook Developers Group
- [X] I've read the Code of Conduct
- [X] This issue is not security related and can safely be disclosed publicly on GitHub
Java version
11
Android version
Android 13
Android SDK version
14.1.0
Installation platform & version
Gradle 7.4.1
Package
Login
Goals
I can log in with androidx.activity 1.5.1 without the Facebook app.
Expected results
I can retrieve the results of your login.
Actual results
Unable to retrieve login results.
not called onActivityResult
or ActivityResultCallback
Steps to reproduce
- I have not installed the Facebook application.
- call
LoginManager#logInWithReadPermissions()
orlaunch(Collection<String>)
- Open CustomTab
- Log in
Code samples & details
No problem in androidx.activity:activity:1.5.0
.
Problem in androidx.activity:activity:1.5.1
.
Change between 1.5.0 and 1.5.1. https://android.googlesource.com/platform/frameworks/support/+log/e047538e9c1a9b12afec093910a556017720cb13..835baf76d995c6653478c7e00946a0558c678c45/activity
import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContract
import androidx.lifecycle.lifecycleScope
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import com.facebook.CallbackManager
import com.facebook.FacebookException
import com.facebook.FacebookSdk
import com.facebook.login.LoginManager
class LoginFacebook(
private val componentActivity: ComponentActivity
) {
private val callbackManager = CallbackManager.Factory.create()
private val facebookLoginManager = LoginManager.getInstance()
private val launcher = object {
private lateinit var launcher: ActivityResultLauncher<Collection<String>>
init {
val contract: ActivityResultContract<Collection<String>, CallbackManager.ActivityResultParameters> =
facebookLoginManager.createLogInActivityResultContract(callbackManager = callbackManager)
componentActivity.lifecycleScope.launchWhenCreated {
launcher = componentActivity.registerForActivityResult(
contract
) {
}
}
}
fun launch() {
launcher.launch(Permissions)
}
}
suspend fun startLogin(): LoginResult {
if (!FacebookSdk.isInitialized()) {
@Suppress("DEPRECATION")
FacebookSdk.sdkInitialize(componentActivity.application)
}
return withContext(Dispatchers.Default) {
try {
suspendCoroutine { continuation ->
val callback = object : com.facebook.FacebookCallback<com.facebook.login.LoginResult> {
override fun onCancel() {
continuation.resumeWithException(IllegalStateException("onCancel"))
}
override fun onError(error: FacebookException) {
continuation.resumeWithException(error)
}
override fun onSuccess(result: com.facebook.login.LoginResult) {
val token = result.accessToken.token
val userId = result.accessToken.userId
continuation.resume(LoginResult(userId = userId, token = token))
}
}
facebookLoginManager.registerCallback(callbackManager, callback)
launcher.launch()
}
} catch (e: Throwable) {
e.printStackTrace()
throw e
} finally {
facebookLoginManager.unregisterCallback(callbackManager)
}
}
}
data class LoginResult(
val userId: String,
val token: String,
)
companion object {
private val Permissions = listOf("public_profile", "user_friends", "email")
}
}
not called https://github.com/facebook/facebook-android-sdk/blob/75d7583f7b02f51ed9034cb1b1f0ced486ec6ecd/facebook-common/src/main/java/com/facebook/login/LoginFragment.kt#L144-L147
same issue in androidx.fragment:fragment:1.5.0
login error in android 11 also
I had the same problem i downgrade temporally to the version 1.5.0 of androidx.activity and androidx.fragment
i used app:dependencies to see which library promote the version 1.5.1 and downgrade too
seems to be fixed. https://github.com/facebook/facebook-android-sdk/commit/d7d4e0d241ea4f9e7035fb12b87b249a10e9af36 https://github.com/facebook/facebook-android-sdk/releases/tag/sdk-version-14.1.0
I will close it when others can confirm it. Please report.
seems to be fixed. d7d4e0d https://github.com/facebook/facebook-android-sdk/releases/tag/sdk-version-14.1.0
I will close it when others can confirm it. Please report.
d7d4e0d is contained in 14.1.1 not 14.1.0 https://github.com/facebook/facebook-android-sdk/releases/tag/sdk-version-14.1.1