消息“ error: resource android: attr/lStar not found”

今天我开发的一个 Flutter Android 应用程序突然编译错了。

错误:

出了什么问题:

任务“ : app: processDebugResources”执行失败。

Android 资源链接失败 /Users/xxx/. gradle/cache/transforms-2/files-2.1/5d04bb4852dc27334fe36f129faf6500/res/values/values.xml: 115:5-162:25: AAPT: error: resource android: attr/lStar not found.

链接引用失败。

我尽力了

使用—— stacktrace 选项运行以获取堆栈跟踪。使用—— info 或—— debug 选项运行以获得更多的日志输出。扫描一下,看看有什么发现。

https://help.gradle.org找人帮忙

构建失败还有16秒。

115912 次浏览

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.

I did this for solving it in my Flutter application.

  1. Open the android/app project
  2. Search the text androidx.core:core-ktx:+ in all solutions. In most cases this is found in build.gradle file.
  3. If you found this text in some dependency, change androidx.core:core-ktx:+ to androidx.core:core-ktx:1.6.0
  4. Sync and run again

In my case, I had this problem with the audioplayers: ^0.17.3 dependency. The + sign was causing the error.

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.

Add the following to your Project build.gradle:

buildscript {
ext {
androidXCore = "1.6.0"
    

}
}

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

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.

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.

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"
}

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.

For Cordova
Uninstall cordova.plugins.diagnostic and cordova-plugin-androidx by running

cordova plugin remove cordova.plugins.diagnostic
cordova plugin remove cordova-plugin-androidx

I removed implementation androidx.core:core:1.7.0, the project did not depend on it, and now everything is OK.

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

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.

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.

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.

I resolved this issue by changing these compileSdkVersion 31, targetSdkVersion 31 and classpath 'com.android.tools.build:gradle:4.0.2'

when craete new project: select Use legacy android.support librares

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

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

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'

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'

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'
}
}

All you have to do is go in build.gradle and erase the entire line:

implementation "androidx.core:core-ktx:+"

super easy

For someone still trying to fix this while all of the above does not help, forcing dependency projects to build on the same SDK worked for me:

subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion = 31
buildToolsVersion = "31.0.0"
}
}
}
}

see https://github.com/react-native-image-picker/react-native-image-picker/issues/882

My situation is a bit different, I'm using mavenPublisher and don't want to upgrade the sdk version, so I need to put the configuration in library/build.gradle, it works for me.

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

Update the following code in your build.gradle(:app) file:

compileSdkVersion 31


targetSdkVersion 31

One major cause for this issue is the Gradle version difference between an added library and the projects build Gradle. This can result to a resource being unavailable during build time. Matching the gradle versions can be an easy fix (If the library is you creation).

Update: This was also related to this for me

None of the other answers worked for me. As a last resort I watched a video in a foreign language and it worked for me. I was compiling to sdk 31

add this in the app build.gradle:

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


dependencies {
implementation "androidx.core:core-ktx:1.6.0"
implementation "androidx.appcompat:appcompat:1.3.0"
}

I got the from Saurabh Kumar but it wasn't working in android/build.gradle for some reason.

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

If you are using React Native and started experiencing this issue later than November 4th 2022, it could be related to the next known issue: https://github.com/facebook/react-native/issues/35210

In order to try if this is what's causing your issue, you can upgrade react-native to the corresponding patch version specified in that link.

Doing that fixed the "error: resource android:attr/lStar not found" issue and two other issues that started suddenly happening for us, so it might be worth a try!

Use this::

 buildscript {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
androidXCore = "1.6.0"
}
}