-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDK initialization causes ANR #1022
Comments
Hi @baole, thanks for raising this issue. We're sorry for the ANR that caused by the Facebook SDK. However, this tracelog cannot happens on the main thread with the latest Facebook SDK. Since If the problem persists, you can choose to disable the auto-init of Facebook. One approach to do manually initializing of Facebook SDK is to add following lines into
Then you can do manually initializing of the Facebook Android SDK by calling
where |
Thanks @linmx0130. It looks like a workaround as I saw https://developers.facebook.com/docs/app-events/gdpr-compliance/#disabling-automatic-sdk-initialization but it doesn't prevent the SDK initialization, at least reading SharedPreferences. Is there any chance to update this behaviour in the future SDK versions? |
Also, |
Hi @baole! Thanks for your response! And for |
@linmx0130 it's not necessary to delete |
@baole That's why I feel strange because all heavy work are already moved to separated threads. As I said, the method that causes ANR in your tracelog cannot be called on the main thread. It may be possible that some devices have strange configurations so that the IO threads make UI freeze... |
@linmx0130 it's still loading SharedPreferences on the thread where it's executing. You can easily check it by enable StrickMode |
@baole Thanks for the report! I will do a fully check on disk IO during the initialization. In our internal testing apps, there are some |
Hi @baole, I think I got what you mean... Facebook Android SDK does access some SharedPreferences during its initialization because according to Google's document, it's safe to do so on main thread by using The ANR reported by Firebase Crashlytics ANR is also not from the main thread. I think they're two independent procedures. We are still working on reducing the time cost in Facebook Android SDK initialization. For now, I would suggest to turn off the auto-init of SDK for now if that's the main reason of long delay in your app start. |
problem is still actual |
|
Hi @linmx0130
More Infomations:
Do you have any opinion on this issue?
|
Checklist before submitting a bug report
Java version
Any
Android version
Any
Android SDK version
Any
Installation platform & version
Gradle
Package
Login
Goals
Facebook SDK currently uses com.facebook.internal.FacebookInitProvider class, a ContentProvider, to initilize its SDK. This class is automatically called on
onCreate()
method during the application (cold) starts. Among other things, it reads data from shared preferences, which reads files on the main thread. In consequence:This is against ContentProvider SDK as it says:
Implement this to initialize your content provider on startup. This method is called for all registered content providers on the application main thread at application launch time. It must not perform lengthy operations, or application startup will be delayed.
Android also suggests to not use SharedPreferences on the main thread and offers DataStore as an alternative API to read/write stored data asynchronously.
It's really bad as Facebook SDK now becomes the main reason causing ANR in our app.
Expected results
No I/O operation in the main thread, no ANR report.
Actual results
Here is one of the report from Firebase Crashlytics ANR
Steps to reproduce
No response
Code samples & details
No response
The text was updated successfully, but these errors were encountered: