facebook-android-sdk
facebook-android-sdk copied to clipboard
Crash FacebookSDK Validate.kt line 129
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
variance
Android SDK version
14.1.1
Installation platform & version
Gradle
Package
Core & AppEvents
Goals
User not facing the crash
Expected results
User not facing the crash
Actual results
This was not happen when using facebook SDK is 11.2.0, only happen after update to 14.1.1 for supporting Android 12+ and adding client Token
I do not know how to reproduce as the crashlytic dashboard show early crash <1 Second. and there is no code reference to our codebase.
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tiket.gits/com.facebook.FacebookActivity}: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3763)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3931)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2356)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:8315)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Caused by com.facebook.FacebookSdkNotInitializedException: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
at com.facebook.internal.Validate.sdkInitialized(Validate.kt:129)
at com.facebook.FacebookSdk.getApplicationId(FacebookSdk.kt:819)
at com.facebook.login.LoginMethodHandler.getRedirectUrl(LoginMethodHandler.kt:83)
at com.facebook.login.CustomTabLoginMethodHandler.getDeveloperDefinedRedirectURI(CustomTabLoginMethodHandler.kt:65)
at com.facebook.login.CustomTabLoginMethodHandler.<init>(CustomTabLoginMethodHandler.kt:208)
at com.facebook.login.CustomTabLoginMethodHandler$Companion$CREATOR$1.createFromParcel(CustomTabLoginMethodHandler.kt:226)
at com.facebook.login.CustomTabLoginMethodHandler$Companion$CREATOR$1.createFromParcel(CustomTabLoginMethodHandler.kt:224)
at android.os.Parcel.readParcelable(Parcel.java:3298)
at android.os.Parcel.readParcelableArray(Parcel.java:3415)
at com.facebook.login.LoginClient.<init>(LoginClient.kt:666)
at com.facebook.login.LoginClient$Companion$CREATOR$1.createFromParcel(LoginClient.kt:707)
at com.facebook.login.LoginClient$Companion$CREATOR$1.createFromParcel(LoginClient.kt:705)
at android.os.Parcel.readParcelable(Parcel.java:3298)
at android.os.Parcel.readValue(Parcel.java:3191)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3584)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:296)
at android.os.BaseBundle.unparcel(BaseBundle.java:240)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:1079)
at androidx.fragment.app.FragmentStateManager.restoreState(FragmentStateManager.java:405)
at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2735)
at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:198)
at androidx.fragment.app.FragmentActivity$2.onContextAvailable(FragmentActivity.java:149)
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:322)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
at com.facebook.FacebookActivity.onCreate(FacebookActivity.kt:58)
at android.app.Activity.performCreate(Activity.java:8151)
at android.app.Activity.performCreate(Activity.java:8135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3732)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3931)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2356)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:8315)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Steps to reproduce
Update Facebook SDK to 14.1.1
Code samples & details
class FacebookAuthImpl(context: Context) : LifecycleObserver, FacebookAuth {
companion object {
@Synchronized
fun initializeSdkIfNeeded(context: Context) {
if (!FacebookSdk.isInitialized()) {
FacebookSdk.setClientToken(BuildConfig.FB_CLIENT_ID)
FacebookSdk.sdkInitialize(context)
}
}
}
init {
initializeSdkIfNeeded(context.applicationContext)
}
private var mSocialAuthCallback: SocialAuthCallback? = null
private var fbAuthIntentResult: ActivityResultLauncher<Collection<String>>? = null
private val facebookCallbackManager by lazy { CallbackManager.Factory.create() }
private val loginManager by lazy { LoginManager.getInstance() }
override fun login(fragment: Fragment) {
val context = fragment.context ?: return
initializeSdkIfNeeded(context.applicationContext)
fbAuthIntentResult?.launch(listOf("email", "public_profile"))
}
override fun login(activity: Activity) {
initializeSdkIfNeeded(activity.applicationContext)
fbAuthIntentResult?.launch(listOf("email", "public_profile"))
}
override fun logout() {
AccessToken.getCurrentAccessToken()?.let {
LoginManager.getInstance().logOut()
}
}
private fun registerFacebookCallback() {
loginManager.registerCallback(facebookCallbackManager, object : FacebookCallback<LoginResult> {
override fun onSuccess(result: LoginResult) {
val successResult = SocialAuthResult.Facebook(
_token = result.accessToken.token
)
mSocialAuthCallback?.onSocialAuthSuccess(successResult)
}
override fun onCancel() {
mSocialAuthCallback?.onSocialAuthCancel()
}
override fun onError(error: FacebookException) {
mSocialAuthCallback?.onSocialAuthFail(
SocialAuthErrorResult.LoginError(
SocialAuthErrorResult.AUTH_SOURCE_FACEBOOK,
error.localizedMessage.orEmpty()
)
)
}
})
}
override fun setup(fragmentActivity: FragmentActivity, socialAuthCallback: SocialAuthCallback) {
mSocialAuthCallback = socialAuthCallback
fbAuthIntentResult = fragmentActivity.registerForActivityResult(
loginManager.createLogInActivityResultContract(facebookCallbackManager)
) {
}
registerFacebookCallback()
registerLifecycleOwner(fragmentActivity)
}
override fun setup(fragment: Fragment, socialAuthCallback: SocialAuthCallback) {
mSocialAuthCallback = socialAuthCallback
fbAuthIntentResult = fragment.registerForActivityResult(
loginManager.createLogInActivityResultContract(facebookCallbackManager)
) {
}
registerFacebookCallback()
registerLifecycleOwner(fragment)
}
private fun registerLifecycleOwner(lifecycleOwner: LifecycleOwner) {
if (lifecycleOwner.lifecycle.currentState == Lifecycle.State.DESTROYED) {
resetCallback()
return
}
lifecycleOwner.lifecycle.removeObserver(this)
lifecycleOwner.lifecycle.addObserver(this)
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun resetCallback() {
fbAuthIntentResult = null
mSocialAuthCallback = null
}
}
@michaeltiket got a bit confused. Were you able to reproduce the issue?. I'm facing exact same issue with the same stack trace. I'm also using 14.1.1. Wondering if you have found a fix for it ?
@sannysinghs no, i am not able to reproduce, and also hasn't found the fix 😢
I face the same issue where the Facebook initialization (SDK version 13.1.0) is delayed.
To reproduce the error, we need to figure out how to trigger (or what triggers) the com.facebook.FacebookActivity
before the main activity.
I have the same issue on the newest 1.6.2
.
Steps to reproduce:
- Start Facebook login. See the Facebook app login screen.
- Go to background.
- Force the Android System to kill your app.
- Go back to your app. See the Facebook app login screen.
- Click the back button -> crash.
Hi @admund , have tried your steps to reproduce, but i still cannot reproduce it on my side. Maybe some question related your step to reproduce
Steps to reproduce:
-
Start Facebook login. See the Facebook app login screen. Question: Open our app, then click login facebook and it open native facebook app right? not the custom tab
-
Go to background.
-
Force the Android System to kill your app. Question: Force kill using, OS App Setting Force stop? or using teminal, is it same like don't keep activities?
-
Go back to your app. See the Facebook app login screen. Question: restore app from background or click the icon app? if restore it will still on facbeook login app
-
Click the back button -> crash. (This step, on my case, it do not crash)
i try using FB SDK 16.1.3
Hi @michaeltiket
- Yes, native Facebook app. But I'm not logged there. This can be important 🤷
- No, the most straightforward way is to revoke some permissions or change language, then your App will be recreated. There was a button for that in old Logcat, but right now, I don't know how to do that from AS.
- Both should work.
Thanks @admund i have reproduced it 🙏 , so the fix is need to merge your changes right?
@michaeltiket you need to build Facebook SDK with this fix and add to your app
Hi @admund , I saw your fix and it works and I was wondering if you are planning to merge it or just keep it open as reference?