material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.39k stars 3.08k forks source link

Rising from 1.3.0-alpha02 to 1.3.0-alpha03 causes `You need to use a Theme.AppCompat theme (or descendant) with this activity` error #1781

Closed RoarGronmo closed 2 years ago

RoarGronmo commented 4 years ago

Description: Did just rise material from com.google.android.material:material:1.3.0-alpha03 to com.google.android.material:material:1.3.0-alpha03

and got this run-time error:

2020-10-07 09:09:45.238 24547-24547/no.norva24.norva24reportertest2 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: no.norva24.norva24reportertest2, PID: 24547
    java.lang.RuntimeException: Unable to start activity ComponentInfo{no.norva24.norva24reportertest2/no.norva24.norva24reportertest2.ui.activities.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        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: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:843)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
        at no.norva24.norva24reportertest2.ui.activities.MainActivity.onCreate(MainActivity.kt:102)
        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) 
        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) 

alpha02 does not produce this error.

Expected behavior: Compile and run as expected, but did not.

Source code: Instead of attaching all my project i attach the dependency trees, if you see any conflicts:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.4.10'
    //ext.kotlin_version = '1.4.0'
    //ext.kotlin_version = "1.4.0-rc"
    //ext.kotlin_version = "1.4-M2"
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url = "https://dl.bintray.com/kotlin/kotlin-eap/" }
        maven { url = "https://kotlin.bintray.com/kotlinx/"}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0-alpha12'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0"
        classpath 'com.google.gms:google-services:4.3.4'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
        classpath 'com.google.firebase:perf-plugin:1.3.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url = "https://dl.bintray.com/kotlin/kotlin-eap/" }
        maven { url = "https://kotlin.bintray.com/kotlinx/" }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'kotlin-android-extensions'
    id 'androidx.navigation.safeargs.kotlin'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
    id 'com.google.firebase.firebase-perf'
}

android {

    signingConfigs {
        debug
        release 
    }

    if(project.hasProperty("AndroidProject.signing")
        && new File(project.property("AndroidProject.signing").toString()).exists())
    {
        def Properties props = new Properties()
        def propFile = new File(project.property("AndroidProject.signing").toString())
        if(propFile.canRead())
        {
            props.load(new FileInputStream(propFile))
            if(props!=null)
            {
                if(props.containsKey('RELEASE_STORE_FILE') &&
                        props.containsKey('RELEASE_STORE_PASSWORD') &&
                        props.containsKey('RELEASE_KEY_ALIAS') &&
                        props.containsKey('RELEASE_KEY_PASSWORD') &&
                        props.containsKey('DEBUG_STORE_FILE') &&
                        props.containsKey('DEBUG_STORE_PASSWORD') &&
                        props.containsKey('DEBUG_KEY_ALIAS') &&
                        props.containsKey('DEBUG_KEY_PASSWORD'))
                {
                    android.signingConfigs.release.storeFile = file(props['RELEASE_STORE_FILE'])
                    android.signingConfigs.release.storePassword = props['RELEASE_STORE_PASSWORD']
                    android.signingConfigs.release.keyAlias = props['RELEASE_KEY_ALIAS']
                    android.signingConfigs.release.keyPassword = props['RELEASE_KEY_PASSWORD']
                    android.signingConfigs.debug.storeFile = file(props['DEBUG_STORE_FILE'])
                    android.signingConfigs.debug.storePassword = props['DEBUG_STORE_PASSWORD']
                    android.signingConfigs.debug.keyAlias = props['DEBUG_KEY_ALIAS']
                    android.signingConfigs.debug.keyPassword = props['RELEASE_KEY_PASSWORD']
                }
                else
                {
                    throw new Exception("Missing properties in:"+propFile.toPath())
                }
            }
        }
        else
        {
            throw new FileNotFoundException("Property file not found: "+propFile.toPath())
        }
    }

    def versionPropsFile = file('version.properties')
    def versionMajor = 0
    def versionMinor = 2
    def versionBuild
    def versionAppDatabase = 24

    if(versionPropsFile.canRead())
    {
        Properties versionProps = new Properties()
        versionProps.load(new FileInputStream(versionPropsFile))
        versionBuild = versionProps['VERSION_BUILD'].toInteger()
    } else {
        throw new FileNotFoundException("Could not read version.properties or its internals ! ")
    }

    ext.autoIncrementBuildNumber =
            {
                if(versionPropsFile.canRead())
                {
                    Properties versionProps  = new Properties()
                    versionProps.load(new FileInputStream(versionPropsFile))
                    versionBuild = versionProps['VERSION_BUILD'].toInteger()+1
                    versionProps['VERSION_BUILD'] = versionBuild.toString()
                    versionProps.store(versionPropsFile.newWriter(),null)
                }
                else
                {
                    throw new FileNotFoundException("Could not read version.properties or its contents ! ")
                }
            }

    gradle.taskGraph.whenReady {
        taskGraph ->
            if(taskGraph.hasTask(assembleDebug))
            {
                autoIncrementBuildNumber()
            }
            else if (taskGraph.hasTask(assembleRelease))
            {
                autoIncrementBuildNumber()
            }
            else if (taskGraph.hasTask(bundleDebug))
            {
                autoIncrementBuildNumber()
            }
            else if (taskGraph.hasTask(bundleRelease))
            {
                autoIncrementBuildNumber()
            }
    }

    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "no.norva24.norva24reportertest2"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 11
        versionName versionMajor+"."+versionMinor+"."+versionCode+"."+versionAppDatabase+"."+versionBuild

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        buildConfigField("long","TIMESTAMP", System.currentTimeMillis()+"L")
        buildConfigField("int","APPDATABASEVERSION","${versionAppDatabase}")
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            resValue("string", "google_maps_key","-omitted-")
        }
        debug {
            resValue("string", "google_maps_key","-omitted-")
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    packagingOptions{
        exclude("META-INF/jersey-module-version")
    }
    buildFeatures {
        dataBinding = true
        compose = false
        viewBinding = true
    }
}

dependencies {

    //Kotlin
    //Stdlib
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    //Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'

    //Androidx
    //Core
    //implementation 'androidx.core:core-ktx:1.4.0-alpha01'
    implementation 'androidx.core:core-ktx:1.5.0-alpha04'

    //AppCompat
    implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
    //implementation 'androidx.appcompat:appcompat:1.2.0'

    //CameraX
    implementation 'androidx.camera:camera-camera2:1.0.0-beta10'
    implementation 'androidx.camera:camera-lifecycle:1.0.0-beta10'
    implementation 'androidx.camera:camera-view:1.0.0-alpha17'

    //ConstraintLayout
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'

    //Navigation
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'

    //Fragment
    implementation 'androidx.fragment:fragment-ktx:1.3.0-beta01'

    //Lifecycle
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-beta01'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-beta01'

    //Legacy
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    //Room
    implementation 'androidx.room:room-runtime:2.3.0-alpha02'
    kapt 'androidx.room:room-compiler:2.3.0-alpha02'
    implementation 'androidx.room:room-testing:2.3.0-alpha02'
    implementation 'androidx.room:room-ktx:2.3.0-alpha02'

    //Preference
    implementation 'androidx.preference:preference-ktx:1.1.1'

    //Local Broadcast Manager
    implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0-alpha01'

    //RecyclerViewStyling
    implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha06'

    //Microsoft
    //Identity
    implementation ('com.microsoft.identity.client:msal:2.0.1')
            {exclude group: 'com.microsoft.device.display'}

    //Graph
    implementation 'com.microsoft.graph:microsoft-graph:2.2.0'

    //Google
    //Material
    implementation 'com.google.android.material:material:1.3.0-alpha03'

    //Guava, to avoid conflict on ListenableFuture on jetified-guava-20.0 (com.google.guava:guava:20.0)
    // and jetified-listenablefuture-1.0 (com.google.guava.listenablefuture:1.0)
    // https://stackoverflow.com/questions/56639529/duplicate-class-com-google-common-util-concurrent-listenablefuture-found-in-modu
    //implementation 'com.google.guava:guava:28.2-android'
    implementation 'com.google.guava:guava:29.0-jre'

    //Firebase
    //Analytics
    implementation 'com.google.firebase:firebase-analytics-ktx:17.5.0'

    //Crashlytics
    implementation 'com.google.firebase:firebase-crashlytics-ktx:17.2.2'

    //Performance analysis
    implementation 'com.google.firebase:firebase-perf:19.0.9'

    //Play-Services
    //Maps
    implementation 'com.google.android.gms:play-services-maps:17.0.0'

    //Maps utilities
    implementation 'com.google.maps.android:android-maps-utils:2.0.3'

    //Location
    implementation 'com.google.android.gms:play-services-location:17.1.0'

    //Square Open Source
    //Retrofit2
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    //OkHttp3
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
    implementation 'com.squareup.okhttp3:okhttp:4.9.0'

    //Tests
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

Android API version: API30

Material Library version: 1.3.0-alpha03

Device: Emulator API30: Pixel 4 API 30

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

RG

RoarGronmo commented 4 years ago

Here's my two themes used

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme.    -->
    <style name="Theme.Norva24ReporterTest2" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
    <!--style name="Theme.Norva24ReporterTest2" parent="Theme.AppCompat.DayNight.DarkActionBar"-->
    <!-- Primary brand color. -->
        <item name="colorPrimary">@color/primaryColor</item>
        <item name="colorPrimaryVariant">@color/primaryDarkColor</item>
        <item name="colorOnPrimary">@color/primaryTextColor</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/secondaryColor</item>
        <item name="colorSecondaryVariant">@color/secondaryDarkColor</item>
        <item name="colorOnSecondary">@color/secondaryTextColor</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
        <item name="actionOverflowMenuStyle">@style/Theme.Norva24ReporterTest2.PopupOverlay3</item>

        <!--item name="recyclerViewStyle">@style/Theme.Norva24ReporterTest2.RecyclerViewOverlay</item-->
    </style>

    <style name="Theme.Norva24ReporterTest2.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="Theme.Norva24ReporterTest2.PopupOverlay3" parent="@style/Widget.MaterialComponents.PopupMenu.Overflow">
        <item name="android:popupBackground">@color/black</item>
        <item name="android:actionMenuTextColor">@color/white</item>
    </style>

    <!--style name="Theme.Norva24ReporterTest2.RecyclerViewOverlay" parent = "@style/Widget.MaterialComponents.MaterialCalendar">
        <item name="android:background">@color/secondaryDarkColor</item>
    </style-->

    <style name="Theme.Norva24ReporterTest2.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />

    <style name="Theme.Norva24ReporterTest2.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />
</resources>

and night theme

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.Norva24ReporterTest2" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/primaryColor</item>
        <item name="colorPrimaryVariant">@color/primaryDarkColor</item>
        <item name="colorOnPrimary">@color/primaryTextColor</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/secondaryColor</item>
        <item name="colorSecondaryVariant">@color/secondaryDarkColor</item>
        <item name="colorOnSecondary">@color/secondaryTextColor</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
</resources>
hunterstich commented 4 years ago

It looks to me like this is likely not an issue on our end. I don't see any changes between 1.3.0-alpha02 and alpha03 within our themes.

This seems pretty strange. Has anything changed with the theme/context your no.norva24.norva24reportertest2.ui.activities.MainActivity is using? Or the theme for MainActivity being set in your Manifest? Is this happening when running the app or when running tests?

Vidyacharan commented 4 years ago

I am experiencing the same issue with 1.2.0 and 1.2.1 for bottom sheet with a theme extended fromWidget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.

10-19 22:00:06.893 31052 31052 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant). 10-19 22:00:06.893 31052 31052 E AndroidRuntime: at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243) 10-19 22:00:06.893 31052 31052 E AndroidRuntime: at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217) 10-19 22:00:06.893 31052 31052 E AndroidRuntime: at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145) 10-19 22:00:06.893 31052 31052 E AndroidRuntime: at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:76) 10-19 22:00:06.893 31052 31052 E AndroidRuntime: at com.google.android.material.textfield.TextInputEditText.<init>(TextInputEditText.java:65) 10-19 22:00:06.893 31052 31052 E AndroidRuntime: at com.google.android.material.textfield.TextInputEditText.<init>(TextInputEditText.java:58)

hunterstich commented 4 years ago

@RoarGronmo @Vidyacharan Are you all able to post a full sample that I can run and try to debug?

harishrpatel commented 4 years ago

Probably not related, but just in case. I am also seeing similar crash. I get it while trying to integrate a third party SDK. In our case, this SDK worked perfectly fine with 1.1.0 version and app being built with one monolith app module. But now we need to create instant app, so extracted that SDK into a dynamic module and now started seeing this crash. Even with 1.3.0-alpha03, it crashes.

RoarGronmo commented 4 years ago

After updating to Gradle 6.8-milestone-1 but still using kotlin 1.4.10 stable, the problems seem to disappear. Using AS4.2C14.

RG

stpatrick2016 commented 3 years ago

Having the same issue when upgrading from alpha03 to alpha04. Pretty much the same setup as of original poster.

drchen commented 2 years ago

Is this still happening?

drchen commented 2 years ago

I'll close this issue for now due to no further info available. Please feel free to reopen it if this is still happening.