Abel Herlambang
Abel Herlambang

Reputation: 75

Unable to start AuthUI's KickOffActivity (UnsupportedOperationException)

I'm trying to make a simple login using Google app. I've followed all the steps to do it yet somehow it force close when I tried to open the AuthUI's activity. It has a runtime error that says:

    Process: com.example.smkccovid, PID: 17619
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.smkccovid/com.firebase.ui.auth.KickoffActivity}: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f03021e a=3 r=0x7f050032}
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2822)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:251)
        at android.app.ActivityThread.main(ActivityThread.java:6563)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f03021e a=3 r=0x7f050032}
        at android.content.res.TypedArray.getColor(TypedArray.java:469)
        at android.app.Activity.onApplyThemeResource(Activity.java:4262)
        at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java:198)
        at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java:140)
        at android.app.Activity.setTheme(Activity.java:4240)
        at androidx.appcompat.app.AppCompatActivity.setTheme(AppCompatActivity.java:111)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2768)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:251) 
        at android.app.ActivityThread.main(ActivityThread.java:6563) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

I've already tried some answers from other SO questions regarding this, such as updating the AuthUI and Firebase version, manually add the activity into the manifest file, clean and rebuild project, and invalidate caches and restart.

This seems to be where the error take place:

    private val RC_SIGN_IN = 1
    ..
    ..
    ..
    private fun buttonSign() {
        startActivityForResult(
            AuthUI.getInstance()
                .createSignInIntentBuilder()
                .setAvailableProviders(listOf(AuthUI.IdpConfig.GoogleBuilder().build()))
                .build(),
            RC_SIGN_IN)
    } 

EDIT:

Application tag in manifest file:

<application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:replace="android:label">
..
..
..
</application>

Application style and theme used:

<resources>
    <style name="AppTheme" parent="MainTheme">
        <item name="android:windowActivityTransitions">true</item>
        <item name="primaryColor">#0771D5</item>
        <item name="primaryColor2">#2D6494</item>
        <item name="accentColor">#88ECEC</item>
        <item name="accentColor2">#4cbbb9</item>
        <item name="onPrimary">#eaeaea</item>
        <item name="onAccent">#1F232C</item>
    </style>

    <style name="Theme.AppCompat.Translucent" parent="AppTheme">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@color/hintBlack</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@android:style/Animation</item>
    </style>

    <style name="Title" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">20sp</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="SubTitle" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">20sp</item>
    </style>

    <style name="SubTitle2" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:alpha">0.75</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">20sp</item>
    </style>

    <style name="BodyWhite" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">16sp</item>
    </style>

    <style name="BodyWhiteBold" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">16sp</item>
    </style>

    <style name="BodyWhiteSmall" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">14sp</item>
    </style>

    <style name="BodyDark" parent="TextAppearance.AppCompat">
        <item name="android:textColor">?attr/primaryColor2</item>
        <item name="android:textSize">16sp</item>
    </style>

    <style name="BigLabelWhite" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">25sp</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="HugeLabelWhite" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">35sp</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="SmallLabelHint" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/hint</item>
        <item name="android:textSize">11sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textAllCaps">true</item>
    </style>

    <style name="SmallLabelWhite" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">11sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textAllCaps">true</item>
    </style>

    <style name="SmallLabelHint2" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/hint</item>
        <item name="android:textSize">13sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textAllCaps">true</item>
    </style>
    <style name="MainTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

Upvotes: 0

Views: 114

Answers (2)

Abel Herlambang
Abel Herlambang

Reputation: 75

Well, I still don't really know what's the actual problem with the code but when I use com.google.android.gms.auth.api.Auth instead of com.firebase.ui.auth.AuthUI it worked fine already. Though it does say that GoogleApiClient is deprecated but for now I think it's fine to implement it first into the app.

This is my new sign-in function:

    private fun signIn() {
        val options = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build()
        val mGoogleApiClient = GoogleApiClient.Builder(this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, options)
            .build()
        val signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient)
        startActivityForResult(signInIntent, RC_SIGN_IN)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        Log.d("TAG", "firebaseAuthWithGoogle:")

        if (requestCode == RC_SIGN_IN) {
            val task = GoogleSignIn.getSignedInAccountFromIntent(data)
            try {
                val account = task.getResult(ApiException::class.java)!!
                Log.d("TAG", "firebaseAuthWithGoogle:" + account.id)
                firebaseAuthWithGoogle(account.idToken!!)
            } catch (e: ApiException) {
                Log.w("TAG", "Google sign in failed", e)
            }
        }
    }

    private fun firebaseAuthWithGoogle(idToken: String) {
        val credential = GoogleAuthProvider.getCredential(idToken, null)
        auth!!.signInWithCredential(credential)
            .addOnCompleteListener(this) { task ->
                if (task.isSuccessful) {         
                    Log.d("TAG", "signInWithCredential:success" + " " + auth!!.currentUser!!.displayName)
                    goTo(this, MainActivity(), true, null)
                } else {
                    Log.w("TAG", "signInWithCredential:failure", task.exception)
                }
            }
    }

Still waiting for anyone to find the actual problem with it though.

Upvotes: 0

Try to using your custom theme in your AuthUI instance.

AuthUI.getInstance()
                .createSignInIntentBuilder()
                .setAvailableProviders(providers)
                .setTheme(R.style.AppTheme) // Set theme
                .build(),
        RC_SIGN_IN)

Upvotes: 1

Related Questions