问题
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
.
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"
}
回答1:
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!
回答2:
Go to File > Close the Project. Then import it back and restart Android Studio.
回答3:
<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.
回答4:
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
回答5:
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.
回答6:
Maybe you can try one of the following solutions:
- delete
.gradle
folder under the project - if the project is imported from Eclipse, or it is an old project
- upgrade
minSdkVersion
inapp/build.gradle
, eg. 14 or 16, which is greater than 8 ! - remove the
minSdkVersion
&targetSdkVersion
configuration inAndroidManifest.xml
!
- upgrade
- import
com.android.support:appcompat-v7
library inapp/build.gradle
- upgrade your Android Studio to the latest version
- if it still doesn't work, maybe you can:
- restart Android Studio
- delete the project in Android Studio and reimport it.
回答7:
compile 'com.android.support:appcompat-v7:23.4.0'
try this
回答8:
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'
}
回答9:
Change in style.xml file as <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"></style>
回答10:
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.
回答11:
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'
}
回答12:
This works for me.
- Close android studio project.
- Remove project from recent.
- Go to project directory and delete ".gradle" directory.
- Open project from option "Open an existing Android Studio Project".
回答13:
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"/>
回答14:
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
andlibraries
directories - File -> Invalidate Caches -> Restart
回答15:
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!
回答16:
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
回答17:
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
.
回答18:
The fix for me was to delete the .gradle folder in my project root, then click file and click "Synchronize". everything worked after that.
回答19:
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.........
来源:https://stackoverflow.com/questions/43177304/cannot-resolve-symbol-theme-appcompat-light-darkactionbar-in-styles-xml