Binary XML file line ... :layout/activity_main: Error inflating class Button

Binary XML file line ... :layout/activity_main: Error inflating class Button
Photo by Tony Pepe / Unsplash

При разработке приложения наткнулся на ошибку:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.savenkoff.demoweatherapp/com.savenkoff.demoweatherapp.MainActivity}: android.view.InflateException: Binary XML file line #48 in com.savenkoff.demoweatherapp:layout/activity_main: Binary XML file line #48 in com.savenkoff.demoweatherapp:layout/activity_main: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3308)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3457)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2044)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7560)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: android.view.InflateException: Binary XML file line #48 in com.savenkoff.demoweatherapp:layout/activity_main: Binary XML file line #48 in com.savenkoff.demoweatherapp:layout/activity_main: Error inflating class Button
Caused by: android.view.InflateException: Binary XML file line #48 in com.savenkoff.demoweatherapp:layout/activity_main: Error inflating class Button
Caused by: java.lang.UnsupportedOperationException: Can't convert to ComplexColor: type=0x1
at android.content.res.ResourcesImpl.loadComplexColorForCookie(ResourcesImpl.java:1184)
at android.content.res.ResourcesImpl.loadComplexColorFromName(ResourcesImpl.java:1039)
at android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:1121)
at android.content.res.Resources.loadColorStateList(Resources.java:1078)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:601)
at android.view.View.<init>(View.java:5699)
at android.widget.TextView.<init>(TextView.java:974)
at android.widget.Button.<init>(Button.java:166)
at android.widget.Button.<init>(Button.java:141)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:81)
at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:234)
at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:230)
at com.google.android.material.theme.MaterialComponentsViewInflater.createButton(MaterialComponentsViewInflater.java:43)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:156)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1678)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1729)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1065)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:775)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:197)
at com.savenkoff.demoweatherapp.MainActivity.onCreate(MainActivity.java:38)
at android.app.Activity.performCreate(Activity.java:7894)
at android.app.Activity.performCreate(Activity.java:7881)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3283)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3457)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2044)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7560)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Описание проблемной секции:

    <Button
        android:id="@+id/main_button"
        android:fontFamily="@font/montserrat_bold"
        android:layout_marginTop="20sp"
        android:layout_marginHorizontal="130sp"
        android:layout_below="@id/user_field"
        android:backgroundTint="@color/material_dynamic_neutral50"
        android:text="@string/main_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

Разработка приложения была под Android 14 ("UpsideDownCake") API level 34, а запуск приложения был на Android 10 ("Q") API level 29.

При попытке открыть структуру проекта (Ctrl + Alt + Shift + S) и понизить API Level до 29:

Получил кучу проблем по зависимостям...

Android Studio упорно требует повысить API level до 33... А как понизить зависимости до 29 API level'a я пока не в курсе.

Нашел другой способ решения проблемы для запуска приложения, удалил android:backgroundTint="@color/material_dynamic_neutral50" , на более старой версии API приложение успешно запустилось.

Продолжаем учиться..