Cannot resolve symbol 'Theme.Material3.Light.NoActionBar' (Android Studio)
Asked Answered
N

5

8

I created a new Android project using Android Studio Arctic Fox | 2020.3.1 Patch 3 and my goal is to simply customize my app to use Material3 theme

Error occurs at values\themes.xml saying Cannot resolve symbol 'Theme.Material3.Light.NoActionBar'

I have found a kinda similar issue on this Question but 'Theme.MaterialComponents.Light.NoActionBar' was my default theme when i created the project and it had no errors, the error started when i changed to use Theme.Material3.Light.NoActionBar as per this article on Migrating to Material Design 3 under section Migrating from M2 to M3 (MDC 1.4.0 to MDC 1.5.0)

I have tried Sync project with gradle files, Invalidate cache /restart.. but i still get the same error

I have used Material Theme builder to generate my themes.xml and colors.xml and below are my files

themes.xml

<resources>
    <style name="Theme.App" parent="Theme.Material3.Light.NoActionBar">
        <item name="colorPrimary">@color/md_theme_light_primary</item>
        <item name="colorOnPrimary">@color/md_theme_light_onPrimary</item>
        <item name="colorPrimaryContainer">@color/md_theme_light_primaryContainer</item>
        <item name="colorOnPrimaryContainer">@color/md_theme_light_onPrimaryContainer</item>
        <item name="colorSecondary">@color/md_theme_light_secondary</item>
        <item name="colorOnSecondary">@color/md_theme_light_onSecondary</item>
        <item name="colorSecondaryContainer">@color/md_theme_light_secondaryContainer</item>
        <item name="colorOnSecondaryContainer">@color/md_theme_light_onSecondaryContainer</item>
        <item name="colorTertiary">@color/md_theme_light_tertiary</item>
        <item name="colorOnTertiary">@color/md_theme_light_onTertiary</item>
        <item name="colorTertiaryContainer">@color/md_theme_light_tertiaryContainer</item>
        <item name="colorOnTertiaryContainer">@color/md_theme_light_onTertiaryContainer</item>
        <item name="colorError">@color/md_theme_light_error</item>
        <item name="colorErrorContainer">@color/md_theme_light_errorContainer</item>
        <item name="colorOnError">@color/md_theme_light_onError</item>
        <item name="colorOnErrorContainer">@color/md_theme_light_onErrorContainer</item>
        <item name="android:colorBackground">@color/md_theme_light_background</item>
        <item name="colorOnBackground">@color/md_theme_light_onBackground</item>
        <item name="colorSurface">@color/md_theme_light_surface</item>
        <item name="colorOnSurface">@color/md_theme_light_onSurface</item>
        <item name="colorSurfaceVariant">@color/md_theme_light_surfaceVariant</item>
        <item name="colorOnSurfaceVariant">@color/md_theme_light_onSurfaceVariant</item>
        <item name="colorOutline">@color/md_theme_light_outline</item>
        <item name="colorOnSurfaceInverse">@color/md_theme_light_inverseOnSurface</item>
        <item name="colorSurfaceInverse">@color/md_theme_light_inverseSurface</item>
        <item name="colorPrimaryInverse">@color/md_theme_light_primaryInverse</item>
    </style>
</resources>

build.gradle (app)

plugins {
    id 'com.android.application'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.blablabla"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildToolsVersion '32.0.0 rc1'
}

dependencies {
    implementation 'androidx.compose.material3:material3:1.0.0-alpha02'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    testImplementation 'junit:junit:'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

buid.gradle (project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"

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

task clean(type: Delete) {
    delete rootProject.buildDir
}
Notation answered 6/1, 2022 at 16:54 Comment(0)
K
7

You have to change the dependency of your material design in your gradle file.

Note: In order to use the new Material3 themes and component styles, you must depend on version 1.5.0-alpha04 or later.

Getting started with MDC android

Visit Google's Maven Repository or MVN Repository to find the latest version of the library.

Kalinin answered 7/1, 2022 at 3:21 Comment(0)
P
6

Just recheck your Gradle dependencies more carefully, there is a difference between

implementation 'androidx.compose.material3:material3:1.2.0-alpha04'

and

implementation 'com.google.android.material:material:1.11.0-alpha01'

While the first one is needed for Jetpack Compose, the second one is for Android MDC. Adding the second one will fix your issue and Theme.Material3.Light.NoActionBar will be accessible from your theme.xml file.

Possible answered 31/7, 2023 at 18:51 Comment(0)
C
3

you have to use alpha version of material dependency

Alpha Release - This is the release when the feature which you are developing is incomplete or partially complete.

Update your material dependency

implementation 'com.google.android.material:material:1.4.0'

to

implementation 'com.google.android.material:material:1.6.0-alpha01'
Cupel answered 7/1, 2022 at 6:47 Comment(0)
H
0
  1. Delete from gradle: runtimeOnly group: 'androidx.appcompat', name: 'appcompat', version: '1.7.0-alpha01' implementation 'com.google.android.material:material:1.7.0'
  2. Sync
  3. Add: runtimeOnly group: 'androidx.appcompat', name: 'appcompat', version: '1.7.0-alpha01' implementation 'com.google.android.material:material:1.7.0'
  4. Sync again
Herta answered 5/12, 2022 at 17:3 Comment(0)
F
0

Update your material dependency

implementation 'com.google.android.material:material:1.4.0'

to

implementation 'com.google.android.material:material:1.7.0-rc01'
Fogg answered 16/2, 2023 at 15:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.