65

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 stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
cizon
  • 761
  • 1
  • 2
  • 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
  • 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
  • 6
    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

23 Answers23

35

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
  • 431
  • 1
  • 1
  • 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
30

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.

  • 2
    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
26

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
  • 1,313
  • 10
  • 15
18

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
  • 573
  • 5
  • 12
  • 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
17

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"
}
Codemaker
  • 7,952
  • 3
  • 61
  • 53
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
  • 1,827
  • 1
  • 15
  • 21
8

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
  • 215
  • 4
  • 5
7

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
  • 71
  • 1
  • 3
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
  • 152
  • 1
  • 11
3

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

Yunnosch
  • 24,749
  • 9
  • 40
  • 51
3

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

Waheed Nazir
  • 494
  • 6
  • 10
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
  • 24,749
  • 9
  • 40
  • 51
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

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'
   }
 }
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
  • 24,056
  • 38
  • 149
  • 245
0

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

  • 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
  • 20,278
  • 4
  • 43
  • 54
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

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