AAPT: error: attribute android:forceDarkAllowed not found

ksgngrkn picture ksgngrkn · May 16, 2019 · Viewed 13k times · Source

Im trying to use android dark theme. I install android studio 3.5 preview.

compileSdkVersion 28 targetSdkVersion 28

but still getting this error. Is this dark theme bug or Im doing something wrong?

build.gradle{
dependencies {
    // ...
    implementation 'com.google.android.material:material:1.1.0-alpha06'
    // ...
  }}

styles.xml

<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
    <item name="android:forceDarkAllowed">true</item>
</style>

project link

https://github.com/googlesamples/android-DarkTheme

Answer

Tash Pemhiwa picture Tash Pemhiwa · Sep 4, 2019

You need to up your compiledSdkVersion to 29, in you app build.gradle:

android {
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        ...
}

Then you should be good to go!