twitter-kit-android icon indicating copy to clipboard operation
twitter-kit-android copied to clipboard

TwitterKit 3 causes black screen for long time on app launching

Open johncodeos opened this issue 7 years ago • 24 comments

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.

johncodeos avatar Jul 04 '17 22:07 johncodeos

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.

efrohnhoefer avatar Jul 05 '17 15:07 efrohnhoefer

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

ghost avatar Jul 07 '17 09:07 ghost

This problem still exists in 3.1.0

johncodeos avatar Jul 30 '17 15:07 johncodeos

Any estimate on when this will be fixed?

stephenmcbride avatar Aug 11 '17 05:08 stephenmcbride

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.

chris-stillwell avatar Aug 11 '17 15:08 chris-stillwell

I found a fix

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

johncodeos avatar Aug 11 '17 15:08 johncodeos

@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

chris-stillwell avatar Aug 23 '17 16:08 chris-stillwell

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

brayanL avatar Aug 30 '17 19:08 brayanL

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

stephenmcbride avatar Sep 11 '17 00:09 stephenmcbride

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

kenyee avatar Sep 24 '17 20:09 kenyee

C'mon now guys, we need a fix.

c0dehunter avatar Oct 23 '17 21:10 c0dehunter

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

polson avatar Nov 01 '17 20:11 polson

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

andon avatar Nov 13 '17 14:11 andon

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.

efrohnhoefer avatar Nov 13 '17 19:11 efrohnhoefer

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

ghost avatar Nov 14 '17 09:11 ghost

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

johncodeos avatar Nov 14 '17 18:11 johncodeos

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

cashjason avatar Dec 17 '17 10:12 cashjason

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) { ... }
    });

chris-stillwell avatar Dec 18 '17 18:12 chris-stillwell

Much better with v3.1.1 for me.

ay8s avatar Jan 28 '18 02:01 ay8s

I think it still exists in version 3.2.0

AppGrade-D avatar Feb 14 '18 13:02 AppGrade-D

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
            }
        })

pamartineza avatar Feb 16 '18 10:02 pamartineza

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

johncodeos avatar Feb 17 '18 21:02 johncodeos

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

pwahid avatar Feb 24 '18 07:02 pwahid

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?

rslama avatar Mar 13 '18 14:03 rslama