为啥 TwitterLoginButton 在 Android 上不会膨胀?

Posted

技术标签:

【中文标题】为啥 TwitterLoginButton 在 Android 上不会膨胀?【英文标题】:Why TwitterLoginButton does not get inflated on Android?为什么 TwitterLoginButton 在 Android 上不会膨胀? 【发布时间】:2019-01-06 16:20:10 【问题描述】:

我只是将 TwitterLoginButton 添加到我的 LoginActivity 并且应用程序停止并出现此异常:

膨胀类 com.twitter.sdk.android.core.identity.TwitterLoginButton 时出错

查看我的 xml 片段

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

    <android.support.constraint.ConstraintLayout
        android:layout_
        android:layout_
        android:fitsSystemWindows="true">

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

另外,有没有办法在没有 TwitterLoginButton 的情况下实现 Twitter 登录? 我找到了这个解决方案,但它对我不起作用,因为我无法导入 TwitterAuthClient

Twitter login without TwitterLoginButton

另外,查看我的 gradle 依赖项

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'

【问题讨论】:

你初始化fabric了吗? 输入你的 gradle 代码。 @LeviMoreira no @AbhayKoradiya 更新了问题 Twitter SDK 在哪里? 【参考方案1】:

根据docs,您需要在应用程序类onCreate 中使用fabric 初始化Twitter 身份验证:

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

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

【讨论】:

以上是关于为啥 TwitterLoginButton 在 Android 上不会膨胀?的主要内容,如果未能解决你的问题,请参考以下文章

为啥 Scala 类型推断在这里失败?

急求!!!在python语言中,列表中能否包含元组,为啥?元组中能否包含列表,为啥? 谢谢大神

为啥 Ruby 中的 `a = a` `nil`?

为啥 a:hover 在 CSS 中会被覆盖?

为啥 Ctrl + A 在 CEdit 中不起作用?

为啥 &a 在 main() 和其他方法中显示不同的值?