Search code examples
javac#xamarinxamarin.androidmaui

Java.Lang.IllegalArgumentException .NET MAUI


After installing BarcodeScanner.Mobile version 8.0.0.1 I get this exception when the application starts: MAUI Java.Lang.IllegalArgumentException: 'This component requires that you specify a valid TextAppearance attribute. Update your app theme to inherit from Theme.MaterialComponents (or a descendant).'

Does anyone got the same experience?


Solution

  • I don't know which part of my app requires an Material design but this is what I do to fix this crash:

    1. In Platform/Android/Resources/values added styles.xml and inside added this code:
    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
       <style name="AppTheme" parent="Theme.MaterialComponents.Light.Bridge">
           <!-- Customize your theme here. -->
           <item name="colorPrimary">@color/colorPrimary</item>
           <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
           <item name="colorAccent">@color/colorAccent</item>
       </style>
    </resources>
    
    1. Make styles.xml Build Action AndroidResource
    2. In AndroidManifest.xml in the <manifest> tag added this lines of code:xmlns:tools="http://schemas.android.com/tools" android:theme="@style/AppTheme" tools:replace="android:theme"
    3. In MainActivity.cs replace the Theme attribute property like this: [Activity(Theme = "@style/AppTheme"....)]

    All this changes fixed my problem with the Java.Lang.IllegalArgumentException