116

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
cizon
  • 1,271
  • 2
  • 4
  • 4
  • 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. – farhan riaz Sep 02 '21 at 15:37
  • 3
    I found same issue in React Native – Richardson. M Sep 02 '21 at 19:50
  • https://stackoverflow.com/questions/69021225/resource-linking-fails-on-lstar – Eduardo Carminati Sep 03 '21 at 12:18
  • 20
    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. – durbnpoisn Dec 01 '21 at 11:44
  • If you are using Kotlin in Java based project, make sure you add only:apply plugin: 'kotlin-android', **NOT** apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt'. I had the same error and they turned out to be the problem. – msc87 Jul 20 '22 at 14:16
  • Set compileSdkVersion up to 31 – Style-7 Oct 13 '22 at 08:36
  • 10
    If you're using React Native and coming here after November 4, 2022, this may be the solution: https://github.com/facebook/react-native/issues/35210 React Native team messed something up and cost a few of us hours! – mavili Nov 06 '22 at 10:32
  • @mavili I thought I was going crazy! Thank you!!! – Mark Nov 07 '22 at 00:06
  • @mavili Thank you !! My app was working on the morning and afternoon it didn't! thank you – sc0rp10n.my7h Nov 08 '22 at 06:46
  • Another possible fix for React Native 70.6 https://github.com/mixpanel/mixpanel-react-native/issues/164#issuecomment-1260920066 – Ryan Pfister Nov 22 '22 at 11:45
  • Above all these if you are facing this error at certain point of time like previous build was success and new builds are not working (release). Then please validate the pubspecs.lock file. – Ganesh Kanna Apr 15 '23 at 12:56

34 Answers34

54

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.

Saurabh Kumar
  • 2,088
  • 14
  • 17
40

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.

Nitrix
  • 481
  • 1
  • 2
  • 3
  • 1
    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' } } – San Sep 30 '21 at 21:00
  • 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! – Armando Peña Oct 01 '21 at 15:49
  • I'm glad it helped, thanks for your feedback :) – Nitrix Oct 01 '21 at 17:12
  • 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. – gautamsinh mori Oct 06 '21 at 07:58
  • 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' – Waheed Nazir Mar 17 '22 at 06:46
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.

  • 3
    Still facing the same issue tried your hack as well – farhan riaz Sep 03 '21 at 05:58
  • 1
    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. – novas1r1 Sep 07 '21 at 08:03
  • 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: https://github.com/luanpotter/audioplayers/issues/999 – troyshu Sep 08 '21 at 14:46
  • Thank you, you saved me from invalidating the cache for 6th time! – Top4o Dec 13 '21 at 07:09
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.

iOS_Mouse
  • 754
  • 7
  • 13
  • 1
    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. – jackofallcode May 17 '22 at 09:42
  • for me worked app compat version is 1.2.0 – Willey Hute May 27 '22 at 17:59
22

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

Bhavesh Chand
  • 495
  • 6
  • 7
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.

  • Seems not working after updating the netinfo package. – Richardson. M Sep 02 '21 at 20:07
  • 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. – CoatedMoose Oct 22 '21 at 19:51
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"
}
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
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.

Mudit Goel
  • 196
  • 1
  • 5
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

Karthik Kompelli
  • 2,104
  • 1
  • 19
  • 22
5

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

Waheed Nazir
  • 584
  • 7
  • 11
  • 2
    What do you change them to, and from what? – TheRealChx101 Jan 05 '22 at 16:08
  • 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 – Waheed Nazir Feb 07 '22 at 04:58
  • 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. – ch271828n May 30 '23 at 13:24
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!

Edu Zamora
  • 1,492
  • 1
  • 19
  • 30
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'
   }
 }
3

Add the following to your Project build.gradle:

buildscript {
  ext {
    androidXCore = "1.6.0"
    
  }
}
user1829870
  • 83
  • 1
  • 7
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.

Shivakumar N.R
  • 170
  • 1
  • 12
3

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

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
3

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

compileSdkVersion 31

targetSdkVersion 31
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
Yunnosch
  • 26,130
  • 9
  • 42
  • 54
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'

Bouchra
  • 11
  • 1
1

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

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

super easy

  • Hi there, please edit your answer with proper code formatting. You can follow the answer in this link https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks – dpacman Apr 12 '22 at 08:34
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'
        }
    }
Alita
  • 587
  • 1
  • 6
  • 16
1

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

Alfaiz Khan
  • 91
  • 1
  • 8
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.

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

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.

Johann
  • 27,536
  • 39
  • 165
  • 279
0

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

sadegh salehi
  • 11
  • 1
  • 3
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30673805) – Anatolii Shuba Dec 29 '21 at 05:24
0

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

Braian Coronel
  • 22,105
  • 4
  • 57
  • 62
0

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'
Junaid
  • 35
  • 3
0

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

Jiří
  • 415
  • 6
  • 16
0

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'
   }
 }
csdroid
  • 11
  • 2
0

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).

Granson
  • 128
  • 1
  • 4
0

Use this::

 buildscript {
     ext {
            buildToolsVersion = "31.0.0" 
            minSdkVersion = 21
            compileSdkVersion = 31
            targetSdkVersion = 31
            androidXCore = "1.6.0"
       }
}
hkniyi
  • 263
  • 3
  • 7
0

This worked for me -

  1. Update RN - https://github.com/facebook/react-native/issues/35210
  2. Add android:exported=“true” in AndroidManifest under Activity tag
  3. change compileSdkVersion = 31 and targetSdkVersion = 31 in Android/build.gradle

Good luck!

Asaf Shveki
  • 736
  • 8
  • 11
0

Compare this old version build.gradle to check for changes in dependencies. For me, removing the added

implementation 'androidx.navigation:navigation-fragment:2.5.2'
implementation 'androidx.navigation:navigation-ui:2.5.2'

, solved the problem

enter image description here

Seachal
  • 27
  • 3
0

following worked for me. This overrides the default compile and target SDK version

in your

android/build.gradle

add this

ext {
    compileSdkVersion = 33
    targetSdkVersion = 33
}
M.AQIB
  • 359
  • 5
  • 11