Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Message "error: resource android:attr/lStar not found"

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.

like image 652
cizon Avatar asked Sep 02 '21 15:09

cizon


5 Answers

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.

like image 97
Nitrix Avatar answered Oct 13 '22 02:10

Nitrix


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.

like image 42
Maikol Bonilla Gil Avatar answered Oct 13 '22 03:10

Maikol Bonilla Gil


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.

like image 30
Saurabh Kumar Avatar answered Oct 13 '22 02:10

Saurabh Kumar


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.

like image 23
iOS_Mouse Avatar answered Oct 13 '22 02:10

iOS_Mouse


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.

like image 17
Kadir Akbulut Avatar answered Oct 13 '22 03:10

Kadir Akbulut