FirebaseUI: AuthMethodPickerActivity crashes when using attrs in theme.
Step 1: Are you in the right place?
- I hope
Step 2: Describe your environment
- Android device: Both emulators and One Plus Nord
- Android OS version: 10 & 11
- Google Play Services version: 21.09.15
- Firebase/Play Services SDK version: 4.3.5 (com.google.gms:google-services)
- FirebaseUI version: 7.1.1
Step 3: Describe the problem:
The app crashes as soon as I try to open FirebaseUI created by this code:
authLauncher.launch(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setIsSmartLockEnabled(false)
.setAvailableProviders(
arrayListOf(
AuthUI.IdpConfig.GoogleBuilder().build(),
AuthUI.IdpConfig.EmailBuilder().build(),
)
)
.setTheme(R.style.AuthUITheme)
.setLogo(R.drawable.logo_no_bg)
.build()
)
This is R.style.AuthUITheme:
<style name="AuthUITheme" parent="FirebaseUI">
<item name="colorPrimary">?colorPrimary</item>
<item name="colorPrimaryDark">?colorPrimaryVariant</item>
<item name="colorAccent">?colorAccent</item>
</style>
Observed Results:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.scitalys.android.ballscalculator.debug, PID: 4913
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.scitalys.android.ballscalculator.debug/com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity}: android.view.InflateException: Binary XML file line #27 in com.scitalys.android.ballscalculator.debug:layout/abc_screen_toolbar: Binary XML file line #27 in com.scitalys.android.ballscalculator.debug:layout/abc_screen_toolbar: Error inflating class androidx.appcompat.widget.ActionBarContainer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.view.InflateException: Binary XML file line #27 in com.scitalys.android.ballscalculator.debug:layout/abc_screen_toolbar: Binary XML file line #27 in com.scitalys.android.ballscalculator.debug:layout/abc_screen_toolbar: Error inflating class androidx.appcompat.widget.ActionBarContainer
Caused by: android.view.InflateException: Binary XML file line #27 in com.scitalys.android.ballscalculator.debug:layout/abc_screen_toolbar: Error inflating class androidx.appcompat.widget.ActionBarContainer
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:899)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:809)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity.onCreate(AuthMethodPickerActivity.java:109)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0400e5 a=7}
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:997)
at android.content.res.TypedArray.getDrawable(TypedArray.java:981)
at androidx.appcompat.widget.ActionBarContainer.<init>(ActionBarContainer.java:67)
... 30 more
EDIT: The problem is about attrs. If I use color references it works. At this point I don't know if it is a bug anymore, but for sure it looks buggish.
@beneventolorenzo thanks for following up with the edit. I am not familiar with this syntax:
<style name="AuthUITheme" parent="FirebaseUI">
<item name="colorPrimary">?colorPrimary</item>
<item name="colorPrimaryDark">?colorPrimaryVariant</item>
<item name="colorAccent">?colorAccent</item>
</style>
I've seen this:
<item name="colorPrimary">?attr/colorPrimary</item>
Does that change anything?
@samtstern no, it doesn't change anything as far as I know! It's just a faster way to type it.
@beneventolorenzo I don't believe that's true. Can you try the longer format? Also this would all be much easier to debug if you could find a way to replicate this crash in the sample app included in this repo.
@samtstern I tried the longer format and it crashes in the exact same way.
Android docs say:
To reference a style attribute, the name syntax is almost identical to the normal resource format, but instead of the at-symbol (@), use a question-mark (?), and the resource type portion is optional. For instance:
?[<package_name>:][<resource_type>/]<resource_name>
My understanding is that the "attr/" part is just optional.
I will try to replicate it in the sample app and report back if I can do it!
Update, just modifying GreenTheme in app/res/styles/ like so reproduces the crash I was experiencing in my app.
<style name="GreenTheme">
<item name="colorPrimary">?colorPrimary</item>
<item name="colorPrimaryDark">@color/material_green_700</item>
<item name="colorAccent">@color/material_purple_a700</item>
<item name="android:windowBackground">@color/material_green_50</item>
</style>
If i replace ?colorPrimary with ?attr/colorPrimary it crashes anyway.
What does this line supposed to mean?
<item name="colorPrimary">?(attr/)colorPrimary</item>
Isn't it cyclic reference to itself? In such case it should rather be omitted altogether.