Message "error: resource android:attr/lStar not found"
AndroidFlutterGradleAndroid Problem Overview
A Flutter Android app I developed suddenly compiled wrong today.
Error:
What went wrong:
Execution failed for task ':app:processDebugResources'. > Android resource linking failed /Users/xxx/.gradle/caches/transforms-2/files-2.1/5d04bb4852dc27334fe36f129faf6500/res/values/values.xml:115:5-162:25: AAPT: error: resource android:attr/lStar not found.
error: failed linking references.
I tried
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
https://help.gradle.org
Get more help atThe build failed in 16 seconds.
Android Solutions
Solution 1 - Android
For those who have this issue in a Cordova
application context like me and using an Android API version older than 31
(29
in my case), I found a clean way to bypass it.
TL;DR
If you are using the plugin cordova.plugins.diagnostic
, uninstall it first then reinstall it using the following argument:
cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.0.0
Refresh the whole android platform and you're project should not be using the androidx.core:core:1.7.0-beta02
anymore.
Full explaination
Solutions already mentionned in the thread (gradle rules to force a certain version of a package) will not work with Cordova
as it handles the whole gradle process on it's own (gathering plugins dependencies, config.xml settings and processing everything) and it's really difficult to override specific things.
I did not manage to fix our problem using resolutionStrategy
for example.
And migrating to Android API 31
isn't always an easy solution (plugins & dependencies need to support it in particular)
Instead, I tried to find which of my installed plugins were having a dependency linked to the androidx.core:core
package, which breaks everything in its 1.7.0-beta02
version.
No one in my list was directly using it, but I found (with the help of the builded build.gradle
) that the following package androidx.appcompat:appcompat
was used and since it's related to AndroidX
as well, I digged a bit and I quickly found-out that the version used for it was 1.+
(latest 1.xx).
Checking on mavenrepo, androidx.appcompat:appcompat
has our buggy package androidx.core:core
as dependency (1.7.0-beta02
on the latest).
After a quick search with my IDE, I found the definition of the dependency :
<framework src="androidx.appcompat:appcompat:$ANDROIDX_VERSION" />
It was used by a plugin named cordova-diagnostic-plugin
. (Pretty common in a Cordova
project, it basically handles Android settings, permissions and hardware stuff)
I noticed that an environment variable was used to define the package version (and set by default to 1.+
).
Going on the plugin's GitHub documentation : https://github.com/dpa99c/cordova-diagnostic-plugin#androidx-library will tell you that you can indeed set a custom version when installing the plugin with the Cordova command.
Which I did (I removed the plugin first):
cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.0.0
After rebuilding the android platform, I started a new build and it was finally successful !
androidx.appcompat:appcompat:1.0.0
was used as well as the androidx.core:core
package in its 1.0.0
version. No more error: resource android attr/lStar not found
issue !
To sum-up : check your plugins dependencies and if possible, set static versions instead of "latest". In that way, you can (in most cases) avoid using alpha/beta releases, which could be instable or not supporting your current environment.
Solution 2 - Android
I did this for solving it in my Flutter application.
- Open the
android/app
project - Search the text
androidx.core:core-ktx:+
in all solutions. In most cases this is found in build.gradle file. - If you found this text in some dependency, change
androidx.core:core-ktx:+
toandroidx.core:core-ktx:1.6.0
- Sync and run again
In my case, I had this problem with the audioplayers: ^0.17.3
dependency. The +
sign was causing the error.
Solution 3 - Android
Using the answer from here Update compileSdkVersion and targetSdkVersion to 31
And add this code snippet in your android/build.gradle file at the very end.
configurations.all {
resolutionStrategy {
force 'androidx.core:core-ktx:1.6.0'
}
}
Just recently the original author of audioplayers package fixed this issue in his recent PR. It has been fixed in audioplayers version 0.20.1
, so if your issue is related to audioplayers, do upgrade.
Solution 4 - Android
I received this error in Android Studio when I created a new Android application. The latest versions of BOTH appcompat and core-ktx in dependencies appear to be the issue.
-
Open build.gradle, and look in dependencies
-
Roll back appcompat to 1.3.0
-
Roll back core-ktx to 1.6.0
-
Tap "Sync Now" (should be in the top right)
dependencies { ... //implementation 'androidx.appcompat:appcompat:1.4.0' //implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'androidx.core:core-ktx:1.6.0' ... }
Rerun your program and cross your fingers.
Solution 5 - Android
Are you using the @react-native-community/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.
Solution 6 - Android
The solution for this error may change according to the platform which we are using for building the application.
For Cordova,
Reinstall cordova.plugins.diagnostic
plugin
cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.0.0
For React Native,
Reinstall @react-native-community/netinfo
library
For Android Studio,
Specify specific or stable version of android core dependency in build.gradle(app) file.
dependencies {
...
implementation "androidx.core:core-ktx:1.6.0"
}
Solution 7 - Android
remove dynamic version in project dependencies in all build.gradle files
example:
"androidx.core:core-ktx:+"
remove + or ^ operator in dependencies { } and mention specific version or stable version
"androidx.core:core-ktx:1.6.0"
source : https://flutter.dev/docs/development/packages-and-plugins/using-packages
Solution 8 - Android
I got the same error
C:\Users\pc.gradle\caches\transforms-2\files-2.1\7a25962662620ee4f1493c07e779c7ef\core-1.7.0\res\values\values.xml:105:5-114:25: AAPT: error:
> resource android:attr/lStar not found.
fix this issue by =
replacing compileSdkVersion 30 in build.gradle
to
> compileSdkVersion 31
Solution 9 - Android
Major source of this issue is appcompat library. As a quick fix to run your project you can use appcompat version below 1.4.0 that is you can switch to appcompat version
implementation 'androidx.appcompat:appcompat:1.3.0'
or below.
Solution 10 - Android
Add the following to your Project build.gradle:
buildscript {
ext {
androidXCore = "1.6.0"
}
}
Solution 11 - Android
If anyone is facing the same issue in ionic cordova, remove these plugin
cordova-plugin-androidx
cordova-plugin-androidx-adapter
And also any plugins dependent on them.
Solution 12 - Android
I removed implementation androidx.core:core:1.7.0
, the project did not depend on it, and now everything is OK.
Solution 13 - Android
I resolved this issue by changing these compileSdkVersion 31
, targetSdkVersion 31
and classpath 'com.android.tools.build:gradle:4.0.2'
Solution 14 - Android
For Cordova
Uninstall cordova.plugins.diagnostic and cordova-plugin-androidx by running
cordova plugin remove cordova.plugins.diagnostic
cordova plugin remove cordova-plugin-androidx
Solution 15 - Android
I solved this problem by down grading my androidx.test.espresso:espresso-core from
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
to
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Solution 16 - Android
this issue appeared with me in flutter and solved it thanks to this answer https://issuetracker.google.com/issues/199180389#comment2 just adding the following to the bottom of our app/build.gradle seemed to work for us while our compileSdkVersion and targetSdkVersion remained at 29:
configurations.all {
resolutionStrategy {
force 'androidx.core:core:1.6.0'
force 'androidx.core:core-ktx:1.6.0'
}
}
Solution 17 - Android
Sorry I cannot comment as I just created an account. Thanks to Nitrix and Codemaker for the hints.
This is the complete list of commands in Ionic just to add to Codemaker's answer to get rid of the not found error
Android resource linking failed /Users/xxx/.gradle/caches/transforms-2/files-2.1/5d04bb4852dc27334fe36f129faf6500/res/values/values.xml:115:5-162:25: AAPT: error: resource android:attr/lStar not found.
npm uninstall cordova.plugins.diagnostic
rm -rf plugins/
rm -rf node_modules/
rm -rf package-lock.json
delete from package.json if diagnostic is still somewhere
npm install
ionic cordova platform rm android
cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.0.0 // This probably cause an error if Capacitor is used or even lately it also causes error with Cordova, so just use the command below
npm install cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.0.0
npm install @ionic-native/diagnostic
ionic cordova platform add android
ionic cordova build android
I hope that this will help a bit.
Solution 18 - Android
comment this line in build.gradle
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//implementation 'androidx.appcompat:appcompat:1.4.0'
that work's for me
Solution 19 - Android
I've had this happen a few times and it always happens when I upgrade my dependencies.
I solved this each time by updating the following items in my gradle files to the latest versions:
- compileSdk
- targetSdk
- compileSdkVersion
- buildToolsVersion
The buildToolsVersion has always been the one that has caused the problem.
Solution 20 - Android
when craete new project: select Use legacy android.support librares
Solution 21 - Android
build.gradle (project)
buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.0.2' } }
build.gradle (:app)
android {
compileSdkVersion 31
defaultConfig {
minSdkVersion 23
targetSdkVersion 31
}
}
dependencies {
def core_version = "1.7.0"
// Java language implementation
implementation "androidx.core:core:$core_version"
// Kotlin
implementation "androidx.core:core-ktx:$core_version"
}
Keep the same configuration of the app module for the feature modules so as not to generate inconsistencies.
GL
Solution 22 - Android
I solved this problem by down grading my appcompat lib from
implementation 'androidx.appcompat:appcompat:1.4.1'
To
implementation 'androidx.appcompat:appcompat:1.1.0'
Solution 23 - Android
All you have to do is go in build.gradle and erase the entire line:
implementation "androidx.core:core-ktx:+"
super easy