AndroidX Build Error: resource android:attr/lStar not found.

Execution failed for task ':launcher:processReleaseResources'.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
/Users/dkt597/.gradle/caches/transforms-2/files-2.1/0d067be99fbc0369149ed6cce206a9e4/androidx.core.core-1.8.0/res/values/values.xml:104:5-113:25: AAPT: error: resource android:attr/lStar not found.

Problem Description

When building Android projects in Unity 2021 or lower, you might encounter an error related to androidx.core:core:1.7.0. This issue arises because Unity 2021 uses SDK build tools version 30.0.2, which does not support compiling androidx.core:core:1.7.0, intended for Android SDK 31 and above.

What You Might See

The build fails, and the error message points to a missing android:attr/lStar attribute, indicating an issue with the AndroidX core library version.

Root Cause

This build error is primarily due to a version compatibility issue between the Android SDK build tools used by Unity 2021 and the version of androidx.core that gets automatically resolved by Google’s External Dependency Manager. Surprisingly, even if the dependencies are explicitly set to use androidx.core:core:1.5.0, the External Dependency Manager overrides this to use version 1.7.0.

Step-by-Step Solution

  1. Disable Auto-Resolution: First, turn off the auto-resolution feature in Unity’s Android Resolver settings to prevent it from automatically updating to incompatible versions.

  2. Remove Incompatible Version: Manually remove the androidx.core:core:1.7.0 library that is being incorrectly added.

  3. Manually Add Compatible Version: Download the androidx.core:core:1.5.0 library directly from Maven and add it manually to the Android plugins folder in the Unity project.

  4. Rebuild the Project: After making these adjustments, the project should build successfully without any errors.

Alternatives and Recommendations

If you're facing this issue, you have a couple of options:

  • Manual Integration: Follow the steps above to manually integrate the correct version of the AndroidX library.

  • Upgrade Unity: Consider upgrading to Unity 2022 or newer. These later versions use SDK build tools version 32.0.0, which are compatible with newer AndroidX versions, thus avoiding this issue entirely.

Last updated