32

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"
    }
Arun
  • 782
  • 2
  • 13
  • 25

20 Answers20

39

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!
Maximilien Belinga
  • 3,076
  • 2
  • 25
  • 39
21

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

Zoe
  • 27,060
  • 21
  • 118
  • 148
eli
  • 8,571
  • 4
  • 30
  • 40
10
<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.

kotoMJ
  • 773
  • 9
  • 18
8

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

Mohammed
  • 1,432
  • 4
  • 18
  • 34
3

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.

Gomino
  • 12,127
  • 4
  • 40
  • 49
1

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.
Scott Wang
  • 489
  • 1
  • 7
  • 9
  • 1
    Thanks. Deleting `.gradle` helped to compile a project. For me another solution helped: https://stackoverflow.com/a/52094111/2914140. – CoolMind Sep 02 '18 at 16:25
0

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'
}
Shishupal Shakya
  • 1,632
  • 2
  • 18
  • 41
0
compile 'com.android.support:appcompat-v7:23.4.0'

try this

0

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

Mohammad Arman
  • 508
  • 4
  • 13
0

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

Oleg Gryb
  • 5,122
  • 1
  • 28
  • 40
0

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'
}
anoop4real
  • 7,598
  • 4
  • 53
  • 56
0

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".
Ketan Ramani
  • 4,874
  • 37
  • 42
0

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"/>
0

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
CoolMind
  • 26,736
  • 15
  • 188
  • 224
0

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!

Community
  • 1
  • 1
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
0

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

Reza
  • 906
  • 2
  • 15
  • 29
0

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.

arlomedia
  • 8,534
  • 5
  • 60
  • 108
0

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

-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.

BSMP
  • 4,596
  • 8
  • 33
  • 44
  • You should be clear what "tried the above" means. You can link directly to an answer that you found did not work. –  Feb 26 '18 at 20:50
-1

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.........

prasad_21
  • 117
  • 2
  • 18
  • Thanks for your answer, but please explain why your solution solves the problem. Also the support libraries posted are for level 26, but the user is compiling against 25. But there is no real warning of the consequences. – Elletlar Jul 21 '18 at 10:06
  • Should we downgrade support libraries? – CoolMind Aug 30 '18 at 09:16
  • @CoolMind:No need to do that, based on your current API use the supporting libraries – prasad_21 Sep 02 '18 at 10:22
  • @Elletlar: Maybe your target API is 26, nut the main thing is it solved your problem.... :) – prasad_21 Sep 02 '18 at 11:04