Android: Resource linking fails on test execution even when nothing has been changed

Viewed 13151

I'm starting to get errors when I am executing a test for a release variant which was always working fine. The code has always been executed in a Docker container so we can ensure that the build will always be clean.

Today for some reason with no changes at all to the code, I am starting to see errors on the test run:

Execution failed for task:
am:processReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     /.gradle/caches/transforms-2/files-2.1/ff28653768e2ccb1135467db3600af3a/core-1.7.0-alpha02/res/values/values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.

I've made some research about the error, but I only find errors related to another resource, but nothing about lStar. So far about, I have found that lStar is code added to Android 31 (Android 12) in particular, which makes no sense to me why it should start working on Android 12 if my compileSdkVersion value is 28.

<declare-styleable name="ColorStateListItem">
    <!-- Base color for this state. -->
    <attr name="android:color"/>
    <!-- Alpha multiplier applied to the base color. -->
    <attr format="float" name="alpha"/>
    <attr name="android:alpha"/>
    <!-- Perceptual luminance applied to the base color. From 0 to 100. -->
    <attr format="float" name="lStar"/>
    <attr name="android:lStar"/>
</declare-styleable>

What could be the cause of this error even though nothing has been changed?

7 Answers

I've found the issue and I was able to fix it.

The issue was that one of the external libraries the app depends on has a dependency on androidx.core:core-ktx:+ which meant that was always compiling with the latest version. My app is still working on SDK 28, but the latest version of androidx.core:core-ktx has the minimal SDK of 31, which resulted in this conflict.

I changed the line androidx.core:core-ktx:+ to androidx.core:core-ktx:1.6.0 in the build.gradle, and it worked for me.

What could be the cause of this error even though nothing has been changed?

As we can see in https://developer.android.com/jetpack/androidx/releases/core#1.7.0-alpha02, Core and Core-ktx Version 1.7.0-alpha02 was released on September 1, 2021.

If you used like androidx.core:core-ktx:+, it would find the last version.

So, on the September 1, 2021, it may be 1.7.0-alpha01 that was not adding the attribute "android:lStar" which need the Android 31 compile SDK. It's a bug.


How can we fix it?

  • use a specific version, use androidx.core:core-ktx:${version} instead of androidx.core:core-ktx:+
  • upgrade the compile SDK to Android 31

Are you using the netinfo library? You need to refresh this library if you are using it.

After updating or uninstalling and reinstalling the netinfo library it will work.

I had used this and it works for me.

  android {  
    configurations.all {
        resolutionStrategy {
            force 'androidx.core:core-ktx:1.6.0'
        }
     }
}

check you added the correct version of

implementation 'com.google.android.material:material:1.3.0'

in dependencies

I used appcompat lib as:

implementation("androidx.appcompat:appcompat:1.3.1")
implementation("androidx.appcompat:appcompat-resources:1.3.1")

Kotlin version as 1.6.0

And it works for me

Related