171

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.

Get more help at https://help.gradle.org

The build failed in 16 seconds.

11
  • Did you find any fix yet? I am facing the same issue. I just tried to re-run my app and everything went wild since then. let me know if you got an answer for this fix. Commented Sep 2, 2021 at 15:37
  • 3
    I found same issue in React Native Commented Sep 2, 2021 at 19:50
  • stackoverflow.com/questions/69021225/… Commented Sep 3, 2021 at 12:18
  • 31
    I would just like to say that this is one of the things that I find SO frustrating with Android development. I opened a brand new project, with the intention of making a simple app with a web view. I added no other code other than the web view. It won't compile because of this error. What a HUGE waste of my time. Especially since I have tried everything this thread and nothing is working. Commented Dec 1, 2021 at 11:44
  • 10
    If you're using React Native and coming here after November 4, 2022, this may be the solution: github.com/facebook/react-native/issues/35210 React Native team messed something up and cost a few of us hours! Commented Nov 6, 2022 at 10:32

40 Answers 40

126

My solution is based on https://github.com/livekit/client-sdk-flutter/issues/569#issuecomment-2275686786

After updating flutter to 3.24, this problem arose again. It is related to the fact that now flutter checks the versions of compileSdkVersion and buildToolsVersion. Some packages either specify outdated versions or do not specify them at all.

As a solution, you need to update your packages to new versions. Also, if you have packages where these parameters are still not specified, you can add a script to your build.gradle between the subprojects instructions. It will look something like this:

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}

// add These lines from here. in android/build.gradle  (NOT android/app/build.gradle)
subprojects {
    afterEvaluate { project ->
        if (project.plugins.hasPlugin("com.android.application") ||
                project.plugins.hasPlugin("com.android.library")) {
            project.android {
                compileSdkVersion 34
                buildToolsVersion "34.0.0"
            }
        }
    }
}
// to here
subprojects {
    project.evaluationDependsOn(':app')
}
Sign up to request clarification or add additional context in comments.

3 Comments

Add these to the android/build.gradle and NOT android/app/build.gradle. Just add the middle subprojects block between the two existing blocks.
This solution worked for me in building the release version. Thank you!
This is work for me, i updated version 36 and "36.0.0"
63

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.

Comments

42

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.

5 Comments

It worked other options. Upgrade to API level 30 by setting defaultTargetSdkVersion & defaultCompileSdkVersion to 30, or by using configurations.all { resolutionStrategy { force 'androidx.core:core:1.6.0' force 'androidx.core:core-ktx:1.6.0' } }
Thanks a lot, I had already investigated this error for 3 hours when I found your answer and worked perfectly. I wanted to thank you yesterday but I had too much to do, so I took the first free time I got to do it! Thank you for sharing!
I'm glad it helped, thanks for your feedback :)
This answer really deserves more hits. To be frank, firstly I ignore this answer but after trying other solutions for two days read your answer carefully and follow the step and its working!!!!!:) thank you, Nitrix.
Should be accepted answer, For my case I don't want to upgrade to target / compile SDK versions so I just kept 1.0.2 to both 'androidx.appcompat:appcompat:1.0.2' and 'androidx.core:core-ktx:1.0.2'
34

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.

4 Comments

Still facing the same issue tried your hack as well
I have the same issue and its gone when I remove the audioplayers dependency. None of the fixes described here worked for me. Still stuck on this.
If you're using audioplayers, update it to ^0.20.0 in your pubspec.yaml. That's what fixed it for me. See discussion here: github.com/luanpotter/audioplayers/issues/999
Thank you, you saved me from invalidating the cache for 6th time!
29

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

1 Comment

Got this err when upgrading androidx fragments and appcompat to 1.4.1. This fixed it.
25

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.

2 Comments

This worked for me, I was updating an older application that was using SDK 29 and appcompat v1.0.0. Updating to latest appcompat (1.4.1 at the time) gave me the lstar error. I didn't even have core-ktx referenced at all, but adding it seems to have fixed my issue.
for me worked app compat version is 1.2.0
18

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.

2 Comments

Seems not working after updating the netinfo package.
This question is about a cordova app, so this answer does not apply. That said, I was having this problem on a react-native app, and ended up on this question. Upgrading @react-native-community/netinfo did resolve my issue.
10

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

Comments

9

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.

Comments

8

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

Comments

6

for ( flutter ) Add or change in android/build.gradle (subprojects) will resolved the issue .

subprojects {
afterEvaluate { project ->
    if (project.plugins.hasPlugin("com.android.application") ||
            project.plugins.hasPlugin("com.android.library")) {
        project.android {
            compileSdkVersion 34
            buildToolsVersion "34.0.0"
        }
    }
}}

2 Comments

Thanks, this worked for me on Flutter 3.24.3
just make sure to place it before: subprojects { project.evaluationDependsOn(':app') }
5

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

3 Comments

What do you change them to, and from what?
Inside app build.gradle change compileSdkVersion and targetSdkVersion to 31 and inside project level build.gradle update com.android.tools.build:gradle to 4.0.2
Similar case here. I upgraded com.android.tools.build:gradle 3.5->7.3, and compileSdkVersion 28->31. Note that these are changed in the package with error, instead of the app.
5

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!

Comments

5

I just fixed this issue by replace ./gradlew assembleRelease by ./gradlew app:assembleRelease

1 Comment

worked for me aswell (RN 0.68)
4

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

Comments

4

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

compileSdkVersion 31

targetSdkVersion 31

Comments

4

None of the mentioned solutions were releated to my problem. I was using image_gallery_saver package in my flutter app and this was throwing the error: image_gallery_saver/intermediates/merged_res/release/values/values.xml:194:%20AAPT:%20error:%20resource%20android:attr/lStar%20not%20found.

When searching for solution, I found out that this dependency was no longer being maintained. So I switched to https://pub.dev/packages/gal package and my error was gone. hope it helps someone.

Comments

3

Add the following to your Project build.gradle:

buildscript {
  ext {
    androidXCore = "1.6.0"
    
  }
}

Comments

3

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.

3 Comments

Why is that? Deprecated?
I am having this issue with ionic cordova right now, can you explain more about it?
cordova-plugin-androidx is deprecated as it's no longer required since cordova-android@9 adds built-in support for AndroidX. This plugin is only needed if your project uses legacy cordova-android@8.
3

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

Comments

2

Fix for Flutter on Windows:

  • Identify the package which causes the problem (in my case it was uni_link3)

  • Find the package cached build.gradle: Usually under C:\Users\xxx\AppData\Local\Pub\Cache\hosted\pub.dev\uni_links3\android\

  • Manually edit the file and change the 'compileSdkVersion' to 34

  • rebuild the release

Comments

1

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

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

Comments

1

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'

Comments

1

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

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

super easy

1 Comment

Hi there, please edit your answer with proper code formatting. You can follow the answer in this link meta.stackoverflow.com/questions/251361/…
1

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

Comments

1

If you are using build.gradle.kts

  1. Open the android/app project

  2. Open build.gradle.kts and replace the subprojects block with this.

    it works like magic

subprojects {
    afterEvaluate {
        if (plugins.hasPlugin("com.android.application") || plugins.hasPlugin("com.android.library")) {
            extensions.findByType<com.android.build.gradle.BaseExtension>()?.apply {
                compileSdkVersion(36)
                buildToolsVersion("36.0.0")
            }
        }
    }
    project.evaluationDependsOn(":app")

}

1 Comment

you saved my life
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.

Comments

0

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

Comments

0

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.

Comments

0

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

1 Comment

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.