Arun
Arun

Reputation: 831

Cannot resolve symbol 'Theme.AppCompat.Light.DarkActionBar' in styles.xml

Theme.AppCompat.Light.DarkActionBar is not compiling in styles.xml. I have added compile 'com.android.support:appcompat-v7:25.1.0' in app module's build.gradle. Theme Error

I have searched for solution in google. A lot of them are about changing the classpath in Project's build.gradle.Still its showing the same error.

build.gradle

dependencies {
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:support-annotations:25.1.0'
    compile 'com.android.support:cardview-v7:25.1.0'
    compile 'com.android.support:recyclerview-v7:25.1.0'
    //    compile 'ch.acra:acra:4.5.0'

    testCompile 'junit:junit:4.12'
}

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 25
        versionCode = 146
        versionName = "0.6.65"
    }

Upvotes: 34

Views: 47187

Answers (20)

Luca Muscarella
Luca Muscarella

Reputation: 11

Try to do Refactor > Migrate to AppCompat.... It worked for me

Upvotes: 1

arlomedia
arlomedia

Reputation: 9061

My theme parent was android:Theme.Light and I wanted to change it to the AppCompat version. I mistakenly changed it to android:Theme.AppCompat.Light, but instead I needed to change it to Theme.AppCompat.Light.

Upvotes: 0

eli
eli

Reputation: 9228

Go to File > Close the Project. Then import it back and restart Android Studio.

Upvotes: 21

Reza
Reza

Reputation: 924

In my case it was due to wrong gradle version in gradle-wrapper.properties.

distributionUrl=https://services.gradle.org/distributions/gradle-5.0-all.zip

Upvotes: 0

Khemraj Sharma
Khemraj Sharma

Reputation: 58934

This solution worked for me

  • Close project (File> Close Project)
  • Import / Re-Open project again (NOT from Recent)

Error should be resolved now.

If that fails, try below-

  • Open build.gradle, remove appcompact-v7 dependency and sync project.
  • Add appcompact-v7 dependency and sync.

Issue solved!

Upvotes: 0

CoolMind
CoolMind

Reputation: 28793

I tried many solutions, including deleting of .gradle folder (yes, it works, a project becomes compilable), but red themes didn't disappear.

This advice helped:

  • Go into the .idea directory
  • Remove caches and libraries directories
  • File -> Invalidate Caches -> Restart

Upvotes: 0

Mohammad Samdi
Mohammad Samdi

Reputation: 111

I have this problem and it is because in my new style and it is because when I declare a new style I put "Theme.AppCompat.Light.NoActionBar" in the name instead of parent. I change from :

<style name="Theme.AppCompat.Light.NoActionBar" />

to

<style name="ThisTheme" parent="Theme.AppCompat.Light.NoActionBar"/>

Upvotes: 0

prasad_21
prasad_21

Reputation: 107

Just remove and add this below lines again in build.gradle i.e. app.gradle and sync it:

implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'

as per your android version.........

Upvotes: -1

Ketan Ramani
Ketan Ramani

Reputation: 5753

This works for me.

  1. Close android studio project.
  2. Remove project from recent.
  3. Go to project directory and delete ".gradle" directory.
  4. Open project from option "Open an existing Android Studio Project".

Upvotes: 0

Scott Wang
Scott Wang

Reputation: 498

Maybe you can try one of the following solutions:

  1. delete .gradle folder under the project
  2. if the project is imported from Eclipse, or it is an old project
    1. upgrade minSdkVersion in app/build.gradle, eg. 14 or 16, which is greater than 8 !
    2. remove the minSdkVersion & targetSdkVersion configuration in AndroidManifest.xml !
  3. import com.android.support:appcompat-v7 library in app/build.gradle
  4. upgrade your Android Studio to the latest version
  5. if it still doesn't work, maybe you can:
    1. restart Android Studio
    2. delete the project in Android Studio and reimport it.

Upvotes: 1

anoop4real
anoop4real

Reputation: 7708

I had the same issue in Android 3.0.1, tried doing "Synchronize", Resysnching gradle etc but nothing helped, I then found that adding

implementation 'com.android.support:design:27.0.2' line fixed the issue

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:support-compat:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:recyclerview-v7:27.0.2'
    implementation 'com.android.support:design:27.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Upvotes: 0

Shawn Experience
Shawn Experience

Reputation: 1

The fix for me was to delete the .gradle folder in my project root, then click file and click "Synchronize". everything worked after that.

Upvotes: -1

Oleg Gryb
Oleg Gryb

Reputation: 5249

I did everything as has been suggested in the accepted answer and it didn't help. Then I did everything as has been suggested in this answer: Android studio cannot find Theme.AppCompat.Light.DarkActionBar (enabled all components in Repository) and it didn't help either.

The issue has been only resolved after clicking on "Synchronized" in File menu. I'm running Android 3.0.1 on Mac.

enter image description here

Upvotes: 0

Mohammed
Mohammed

Reputation: 1504

I have noticed that all themes available with the prefix @android:style/ can be used. So, I have solved this issue by replacing

Theme.AppCompat.Light.DarkActionBar

with

@android:style/Theme.DeviceDefault.Light.DarkActionBar

Upvotes: 9

kotoMJ
kotoMJ

Reputation: 803

<style name="Theme.Base.MyTheme" parent="Theme.AppCompat.Light.NoActionBar">

In case when clean/rebuild not work, just delete .gradle directory in your project root. And sync project with gradle again.

This issue is caused when you mix cache of your support libraries.

Upvotes: 10

Maximilien Belinga
Maximilien Belinga

Reputation: 3186

Your build.gradle version is simply the wrong one.

Follow these instructions to fix that:

  • In Android studio, go to the Gradle scripts section in the left panel.
  • Find the file: build.gradle(Project:{your_project_name})
  • In that file look at the line com.android.tools.build:gradle
  • Check that the version match with your android studio version (for instance 2.3.3). This implies that com.android.tools.build:gradle:2.3.3 and And an Android studio distribution with 2.3.3 as version.
  • Validate the versions are the same. If it's not the case, make sure they match.
  • Rebuild the project and everything is fine!

Upvotes: 40

Gomino
Gomino

Reputation: 12347

I had the exact same problem, what fixed it for me was retrograding gradle plugin:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        //classpath 'com.android.tools.build:gradle:2.3.1'
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

Followed by a project sync with gradle files to clear the problem.

Upvotes: 3

Mohammad Arman
Mohammad Arman

Reputation: 508

Change in style.xml file as <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"></style>

Upvotes: 0

Shishupal Shakya
Shishupal Shakya

Reputation: 1672

Check your build.gradle file , set compileSdkVersion to 25 . Following gradle is working for me with appcompat-v7:25.1.0'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "xxx.xx.xxxxx"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 26
        versionName "3.16"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    //compile 'com.google.firebase:firebase-messaging:9.0.1'
    compile 'com.android.support:appcompat-v7:25.1.0'
}

Upvotes: 0

Hasmukh Kachhatiya
Hasmukh Kachhatiya

Reputation: 488

compile 'com.android.support:appcompat-v7:23.4.0'

try this

Upvotes: 0

Related Questions