6155031
6155031

Reputation: 4347

AAPT: error: attribute android:forceDarkAllowed not found

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

Upvotes: 21

Views: 27947

Answers (5)

Diljeet
Diljeet

Reputation: 1976

I found the answer in android studio suggestions. for clarification the tag android:forceDarkAllowed is only found in api level 29+ so what we should do is create a folder values-v29 and then write the tag in it like below

in file values/____.xml

<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
    //removed from here
</style>

in file values-v29/____.xml

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

Upvotes: 3

Sunny Pradeep
Sunny Pradeep

Reputation: 1

See the Nativescript docs.

Remove below line:

<item name="android:forceDarkAllowed">true</item>

from file

<project>/app/App_Recoures/Android/src/main/res/values/styles.xml

Upvotes: -6

svkaka
svkaka

Reputation: 4032

I was searching for an answer and as @Ruben pointed out)

Changing compiledSdkVersion 28 to compileSdkVersion 'android-Q' should solve the issue. android:forceDarkAllowed attribute was only added in Android Q.

Unrelated to this issue, but it seems like you need to also update 'androidx.appcompat:appcompat:1.1.0-alpha04' to 'androidx.appcompat:appcompat:1.1.0-alpha05' or the theme switching doesn't work properly.

Upvotes: 8

Marci
Marci

Reputation: 41

I encountered the same error message when I tried to run my previously untouched Angular based NativeScript "Hello World" android application. (In command prompt: tns create, tns run android --bundle)

For me the solution was: 1. Open SDK Manager in Android Studio 2. Install Android 10.0 (Q) (API Level: 29) SDK Platform.

After these steps I could start running my app without any errors!

Upvotes: 2

Tash Pemhiwa
Tash Pemhiwa

Reputation: 7685

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!

Upvotes: 20

Related Questions