twitter-archive / twitter-kit-android

Twitter Kit for Android
https://dev.twitter.com/twitterkit/android/overview
Apache License 2.0
831 stars 341 forks source link

TwitterKit 3 causes black screen for long time on app launching #89

Open johncodeos opened 7 years ago

johncodeos commented 7 years ago

Hi, after changing from fabric's twitterkit to twitterkit 3, there is big delay when I'm launching my app. After the splash screen there is a black screen for ~8sec, log says this:

W/Twitter: Could not call isLimitAdTrackingEnabled on com.google.android.gms.ads.identifier.AdvertisingIdClient$Info
D/Twitter: Could not get parcel from Google Play Service to capture AdvertisingId
D/Twitter: Could not get parcel from Google Play Service to capture Advertising limitAdTracking
D/Twitter: AdvertisingInfo not present

I'm not using any ads on my app.

I tested it, removing twitterkit's initialization, and the black screen doesn't appear at all, so is definitely from that.

efrohnhoefer commented 7 years ago

Likely similar to A lot of ANR after Twitter SDK update to 3.0.0. Currently the workaround is to run initialization in the background. We are looking to address the issue in the SDK.

ghost commented 7 years ago

Hi, i have the same bug during my first tweet display in my app.

During the ANR we got two logs from your sdk : W/Twitter: Could not call getAdvertisingIdInfo on com.google.android.gms.ads.identifier.AdvertisingIdClient W/Twitter: Could not call getId on com.google.android.gms.ads.identifier.AdvertisingIdClient$Info

I think it's due to AdvertisingInfoReflectionStrategy.getInfo() method throw an exception because it's forbidden to call com.google.android.gms.ads.identifier.AdvertisingIdClient.getAdvertisingIdInfo in main thread ("java.lang.IllegalStateException: Calling this from your main thread can lead to deadlock") .

So AdvertisingInfoReflectionStrategy.getInfo() return null and AdvertisingInfoReflectionStrategy.isLimitAdTrackingEnabled() got a NullPointerException

Thanks

johncodeos commented 7 years ago

This problem still exists in 3.1.0

stephenmcbride commented 7 years ago

Any estimate on when this will be fixed?

chris-stillwell commented 7 years ago

I get this same issue immediately after calling:

final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(context).setTimeline(userTimeline).build();

My logcat prints the following while the above command is running.

W: Could not call getId on com.google.android.gms.ads.identifier.AdvertisingIdClient$Info
W: Could not call isLimitAdTrackingEnabled on com.google.android.gms.ads.identifier.AdvertisingIdClient$Info
D: Could not get parcel from Google Play Service to capture AdvertisingId
D: Could not get parcel from Google Play Service to capture Advertising limitAdTracking
D: AdvertisingInfo not present
W: Long monitor contention with owner twitter-worker1 (24314) at java.lang.Object dalvik.system.DexFile.openDexFileNative(java.lang.String, java.lang.String, int, java.lang.ClassLoader, dalvik.system.DexPathList$Element[])(DexFile.java:-2) waiters=0 in com.twitter.sdk.android.core.internal.AdvertisingInfo com.twitter.sdk.android.core.internal.IdManager.getAdvertisingInfo() for 20.318s

I'm using com.twitter.sdk.android:twitter:3.1.0 for my project.

johncodeos commented 7 years ago

I found a fix

add new Thread(() -> TweetUi.getInstance()).start(); after Twitter.initialize(this); credits to PiotrWpl here

chris-stillwell commented 7 years ago

@JEKos That isn't much of a fix if you are trying to load a timeline on the main activity as you will still have to wait the 20+ seconds for the initialization to finish before the timeline gets built.

As an aside, the issue is still present in 3.1.1

brayanL commented 7 years ago

Hello, the problem is still persistent, some solution other than the above proposal

stephenmcbride commented 7 years ago

It has been over 2 months since this was first reported, can we get an ETA on when this will be fixed please @efrohnhoefer?

kenyee commented 6 years ago

Getting hit by this too..upgraded a bunch of libraries and chased the weird program pauses to this too :-(

c0dehunter commented 6 years ago

C'mon now guys, we need a fix.

polson commented 6 years ago

Just chiming in that I would also like to see this fixed

andon commented 6 years ago

We are experiencing the same issue. Would like to get this fixed as well.

efrohnhoefer commented 6 years ago

We just released version 3.2.0 that we think addresses the issue. If there is still a problem it would be helpful if someone could provided a sample app that reproduces the issue.

ghost commented 6 years ago

It's seems to work better for me, it's no longer necessary to do : new Thread(() -> TweetUi.getInstance()).start();

johncodeos commented 6 years ago

Problem still exists in 3.2.0, new Thread(() -> TweetUi.getInstance()).start(); solves the problem again for me

cashjason commented 6 years ago

Any updates on a fix for this? The thread did not work for me

chris-stillwell commented 6 years ago

Version 3.1.1 fixed the issue for me. I had to update my code to the following

TwitterConfig config = new TwitterConfig.Builder(this)
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(new TwitterAuthConfig(getTwitterKey(), getTwitterSecret()))
            .debug(true)
            .build();
 Twitter.initialize(config);

And I get the timeline using the following

UserTimeline userTimeline = new UserTimeline.Builder().screenName("...").build();
    userTimeline.next(null, new Callback<TimelineResult<Tweet>>() {
        @Override
        public void success(Result<TimelineResult<Tweet>> result) { ... }
        @Override
        public void failure(TwitterException exception) { ... }
    });
ay8s commented 6 years ago

Much better with v3.1.1 for me.

AppGrade-D commented 6 years ago

I think it still exists in version 3.2.0

pamartineza commented 6 years ago

My working solution that doesn't block UI thread (tested on SDK v3.2.0)

//Twitter sdk initialization
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
TwitterConfig config = new TwitterConfig.Builder(getContext())
                .twitterAuthConfig(authConfig)
                .build();
Twitter.initialize(config);
//Define your userTimeLine
 val userTimeLine = UserTimeline.Builder()
                .screenName(yourHandle)
                .maxItemsPerRequest(10)
                .includeReplies(false)
                .includeRetweets(true)
                .build()

//Request tweets async
userTimeLine.next(null, object: Callback<TimelineResult<Tweet>?>() {
            override fun success(result: Result<TimelineResult<Tweet>?>?) {

               //Once tweets have been retrieved then create your adapter
                val adapter = TweetTimelineListAdapter.Builder(context)
                    .setTimeline(userTimeLine)
                    .build();

                //Set adapter for your listview
                listLv.adapter = adapter
            }

            override fun failure(exception: TwitterException?) {
               //handle failure
            }
        })
johncodeos commented 6 years ago

@pamartineza Yep, I tested it and it working! Thanks!

pwahid commented 6 years ago

On Twitter SDK v3.2.0. Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\mypc\ .gradle\caches\transforms-1\files-1.1\tweet-ui-3.2.0.aar\fff28dafeed80062205ad8b22682a05f\jars\classes.jar

Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing com/twitter/sdk/android/tweetui/FilterTimelineDelegate$TimelineFilterCallback.class

Error:com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)

Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\mypc\ .gradle\caches\transforms-1\files-1.1\tweet-ui-3.2.0.aar\fff28dafeed80062205ad8b22682a05f\jars\classes.jar

my application details- minSdkVersion 21 targetSdkVersion 26

rslama commented 6 years ago

Even v. 3.1.1 somehow works better (in term of freezing UI) than v. 3.2.0 there are still phones which handle that very bad way. Is any plan/schedule for fix?