Why TwitterLoginButton does not get inflated on Android?

222 views Asked by At

I just add TwitterLoginButton to my LoginActivity and app stops with this exception:

Error inflating class com.twitter.sdk.android.core.identity.TwitterLoginButton

See my xml fragment

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_welcome"
    android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <!--<com.twitter.sdk.android.core.identity.TwitterLoginButton-->
            <!--android:id="@+id/button_twitter_login"-->
            <!--android:layout_width="wrap_content"-->
            <!--android:layout_height="wrap_content" />-->
                          .......
        </android.support.constraint.ConstraintLayout>
</ScrollView>

Also, is there a way to implement Twitter sign in without TwitterLoginButton? I found this solution but it didn't work for me, since I couldn't import TwitterAuthClient

Twitter login without TwitterLoginButton

Also, see my gradle dependencies

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    //butterknife
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:design:27.1.1'

    implementation 'com.mikhaellopez:circularimageview:3.0.2'
    implementation 'me.zhanghai.android.materialratingbar:library:1.3.1'

    implementation 'com.iarcuschin:simpleratingbar:0.1.5'

    //authentication
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.facebook.android:facebook-login:4.35.0'


}

apply plugin: 'com.google.gms.google-services'
1

There are 1 answers

0
Levi Moreira On

According to the docs, you need to intialize the Twitter auth with fabric in your application class onCreate:

@Override
public void onCreate() {
    super.onCreate();

    TwitterAuthConfig authConfig =  new TwitterAuthConfig("consumerKey", "consumerSecret");
    Fabric.with(this, new TwitterCore(authConfig));
}