Resource linking fails on lStar

Viewed 60154

I'm working on a React Native application. My Android builds began to fail in the CI environment (and locally) without any changes.

Execution failed for task ':app:processDevelopmentDebugResources'.

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
.../app/build/intermediates/incremental/mergeDevelopmentDebugResources/merged.dir/values/values.xml:2682: AAPT: error: resource android:attr/lStar not found.

According to Android: Resource linking fails on test execution even when nothing has been changed, this happened because some library got upgraded.

lStar needs compileSdkVersion 31 and my project used compileSdkVersion 28.

How can I track which libraries got updated recently, or which library is causing this?

36 Answers

The problem is @react-native-community/netinfo. Just try to update the package using

yarn add @react-native-community/netinfo

or

npm update @react-native-community/netinfo

There isn't any need to change anything over your Gradle or Android files as those might mess things up even more.

Go to android/build.gradle and add androidXCore = "1.6.0" to ext:

ext {
    buildToolsVersion = "29.0.2"
    minSdkVersion = 21
    compileSdkVersion = 29
    targetSdkVersion = 29
    googlePlayServicesAuthVersion = "16.0.1"
    androidXCore = "1.6.0"
}

Native Android:

The issue occurs because of androidx.core:core-ktx.

If you are using core-ktx, change

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

to

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

if you are not using core-ktx maybe one of your dependent libraries is using androidx.core:core-ktx.

Solution 1: Figure out the library using core-ktx and try not to use it.

Or:

Solution 2: Update compileSdkVersion and targetSdkVersion to 31

Or:

Solution 3: In app:build.grandle add below code: hou andy's solution

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

It looks like there is a bug with the alpha02 version of core-ktx.

There might be two reasons that this is happening to you project if you didn't upgrade it recently:

  1. You are using

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

    In this case, replace it with

    implementation "androidx.core:core-ktx:1.6.0" (or whichever version works for you)

  2. Some library is using that alpha02 version

    In this case you have two options:

    1. temporarily increase to compileSdkVersion 31

    2. Remove or downgrade the dependency that is using alpha02

    Run

     ./gradlew :app:dependencies > dependencies.txt
    

    A text file with dependency tree will be added to your project.

    Open the file and you will see something like this

     +--- MyApp:mylibrary:unspecified
     |    \--- com.android.support:appcompat-v7:25.3.1
     |         +--- com.android.support:animated-vector-drawable:25.3.1
     |         |    \--- com.android.support:support-vector-drawable:25.3.1
     |         |         \--- com.android.support:support-v4:25.3.1
     |         |              \--- LOCAL: internal_impl-25.3.1.jar
     |         +--- com.android.support:support-v4:25.3.1
     |         |    \--- LOCAL: internal_impl-25.3.1.jar
     |         \--- com.android.support:support-vector-drawable:25.3.1
     |              \--- com.android.support:support-v4:25.3.1
     |                   \--- LOCAL: internal_impl-25.3.1.jar
     \--- com.android.support:appcompat-v7:25.3.1
          +--- com.android.support:animated-vector-drawable:25.3.1
          |    \--- com.android.support:support-vector-drawable:25.3.1
          |         \--- com.android.support:support-v4:25.3.1
          |              \--- LOCAL: internal_impl-25.3.1.jar
          +--- com.android.support:support-v4:25.3.1
          |    \--- LOCAL: internal_impl-25.3.1.jar
          \--- com.android.support:support-vector-drawable:25.3.1
               \--- com.android.support:support-v4:25.3.1
                    \--- LOCAL: internal_impl-25.3.1.jar
    

    Search for something similar to this

     androidx.core:core-ktx:1.6.0 -> 1.7.0-alpha-02
    

    Track down which dependency is using that. To fix it you might need to either remove the dependency or downgrade it to an older version.

Go to your package.json file and delete as many dependencies as you can until the project builds successfully. Then start adding back the dependencies one by one to detect which ones have troubles.

Then you can manually patch those dependencies by acceding them on node_modules/[dependencie]/android/build.gradle and setting androidx.core:core-ktx: or androidx.core:core: to a specific version (1.6.0 in my case).

Solution for Flutter:

Simply search globally for core-ktx dependencies for all the Flutter packages including the Flutter project android folder and set the 1.6.0 version instead of +.

From:

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

To:

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

I faced the same issue with the audioplayers Flutter package in older version.

Changing android/build.gradle and adding androidXCore = "1.6.0" worked for me.

ext {
    buildToolsVersion = "29.0.2"
    minSdkVersion = 21
    compileSdkVersion = 29
    targetSdkVersion = 29
    googlePlayServicesAuthVersion = "16.0.1"
    androidXCore = "1.6.0"    //Add this line
}

Force use this androidx-core version in your app module file build.gradle:

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

It's seems to work for me!

I changed version 29 to 31 in compileSdkVersion and targetSdkVersion of the build.gradle file in the android folder. It solved my problem.

For Unity Game Engine Builds

In case someone ends up here searching for a solution with their Unity builds, the solution is to add

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

At the end of your launcherTemplate.gradle file in Plugins/Android.

Solution for Cordova

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.

Changing appcompat version to 1.3.0 worked for me

implementation 'androidx.appcompat:appcompat:1.3.0'

In my case, the problem was with react-native-screen-brightness, so I just changed implementation 'androidx.core:core:1+' to implementation 'androidx.core:core:1.6.0' in file android/build.gradle.

In my case problem was with @react-native-community/netinfo": "^5.3.3, so I just removed the netinfo library and installed it again with the latest version and the problem got solved.

Just adding androidXCore = "1.6.0" solved it for me.

If you getting this issue in Android

if you using

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

just replace it with:

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

and in gradle-wrapper.properties: distributionUrl is:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

________________________________________________________________

Other wise

and if you want to use

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

just change distributionUrl in gradle-wrapper.properties:

#distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

I solved it by replacing

implementation 'androidx.core:core:1.0.0'

with this one:

implementation 'androidx.core:core-ktx:1.6.0'

If you have for some reason both, set only the ktx version.

I couldn't figure out which library was causing the problem and upgrading compileSDK version was breaking the app, but I went to the core and you can see that the core library got updated a day back. So the alpha-02 was causing the problem.

I fixed my problem by converting

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

to

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

in the build Gradle file (app level) and then Sync now.

In fact, the answer native android is correct:

"It looks like there is a bug with the alpha02 version of core-ktx"

You are using

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

In this case, replace it with

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

but in many cases, it doesn't help because when you don't use explicit this dependency. What happened is jetbrain convert old library automatically to use androidx latest library, that's the origin of the issue. so you need to check every dependency implement in your build.gradle and update it to androidx version. for me it's a old project, the room before is:

compile "android.arch.persistence.room:runtime:+"   
annotationProcessor "android.arch.persistence.room:compiler:+"

to

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

and you need add this in your build.gradle (you can add it globally in the end of the file):

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

For me, the working solution was updating compileSdkVersion and targetSdkVersion to 31 in the app-level Gradle file.

If you're using compileSdkVersion lower than 31, use 1.6.0.

None of the previous answers worked for me.

I removed the Huawei IAP libraries, but I forgot to delete the agconnect-services.json file provided by Huawei. So after deleting that file, all went well.

Replacing implementation "androidx.core:core-ktx:+" with 'androidx.core:core-ktx:1.6.0' in your project or module level Gradle file will fix the issue. There isn't any need to increase the compileSdkVersion.

It worked for me.

  1. Update Gradle
  2. Update the SDK to version 31
  3. Accept the license
  4. Set compileSdkVersion to 31 in the build Gradle file
  5. Sync

Ready to go!

Find all dependencies in your project:

Replace all: implementation "androidx.core:core-ktx:+" with the specified version: 1.6.0, because with the +, you always use the newest version.

Now androidx.core:core-ktx updates to the 1.7.0-alpha version.

Getting the same error

Solved the issue in may case by

changing

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

implementation "androidx.core:core-ktx:1.6.0"(updated)

issue fixed... thanks to above solution

In my case updating @react-native-community/netinfo to 6.0.2 plus adding coreVersion = "1.6.0" into build.gradle for package @invertase/react-native-apple-authentication which is searching for this variable resolved the issue.

I have resolved my issue by updating the @react-native-community/netinfo library.

npm update @react-native-community/netinfo

core-1.7.0-alpha02

Suddenly build is failing without any code change?

It is quite common. This happened with me many times and most recently it happened with core-1.7.0-alpha02. My project was building fine and one day it stooped.

What might be the issue?

Gradle sync

Sometimes new version of libraries break project.

Solution?

Force you gradle to use the old stable versions. In this case androidx.core:core:1.6.0 was the stable release. You can see always find the stable version information

enter image description here

How to use older version of library?

Go to gradle.build (app level) and paste this

//Forcing 1.6.0 instead of 1.7.0-alpha02
configurations.all {
   resolutionStrategy {
       force 'androidx.core:core:1.6.0'    //This is stable version right now.
   }
}

Bonus:

General rule to fix these issues?

In my case this was the error message

/Users/singhr1/.gradle/caches/transforms-2/files-2.1/1ae857b36375746f9b0fa09af0c656f3/core-1.7.0-beta02/res/values/values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.

So the culprit was core-1.7.0-beta02.
I found the stable version on Developer's page and forced my Gradle to use it.

FOR IONIC CORDOVA, in the build.gradle where all your dependencies are put this

build.gradle

ext {
    buildToolsVersion = "29.0.2"
    minSdkVersion = 21
    compileSdkVersion = 29
    targetSdkVersion = 29
    googlePlayServicesAuthVersion = "16.0.1"
    androidXCore = "1.6.0".  <---------- this is important
}

configurations.all{

resolutionStrategy {
        force 'androidx.core:core:1.6.0' <---------- this is important
        force 'androidx.core:core-ktx:1.6.0'  <-----this is important
    }

}

dependencies

implementation "androidx.core:core-ktx:1.6.0"  <-----this is important
implementation "androidx.core:core:1.6.0" <-----this is important

Update your gradel.build

compileSdkVersion 31
targetSdkVersion 31

For those using ionic 3 and firebase, the solution is change the project.properties and replace some androidx.core lines:

Before

# Project target.
target=android-28
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=androidx.legacy:legacy-support-v4:1.0.0
cordova.gradle.include.1=cordova-support-google-services/nosveja-build.gradle
cordova.system.library.2=com.google.firebase:firebase-analytics:17.5.+
cordova.gradle.include.2=cordova-plugin-firebase-lib/nosveja-build.gradle
cordova.system.library.3=com.google.android.gms:play-services-tagmanager:16.+
cordova.system.library.4=com.google.firebase:firebase-auth:18.+
cordova.system.library.5=com.google.firebase:firebase-core:17.+
cordova.system.library.6=com.google.firebase:firebase-messaging:19.+
cordova.system.library.7=com.google.firebase:firebase-config:18.+
cordova.system.library.8=com.google.firebase:firebase-perf:18.+
cordova.system.library.9=androidx.annotation:annotation:1.1.0
cordova.system.library.10=com.google.android.gms:play-services-location:16.+
cordova.system.library.11=androidx.legacy:legacy-support-v4:1.0.0
cordova.system.library.12=androidx.legacy:legacy-support-v4:1.+
cordova.system.library.13=androidx.appcompat:appcompat:1.+

After

target=android-28
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=androidx.core:core-ktx:1.6.0
cordova.gradle.include.1=cordova-support-google-services/nosveja-build.gradle
cordova.system.library.2=com.google.firebase:firebase-analytics:17.5.+
cordova.gradle.include.2=cordova-plugin-firebase-lib/nosveja-build.gradle
cordova.system.library.3=com.google.android.gms:play-services-tagmanager:16.+
cordova.system.library.4=com.google.firebase:firebase-auth:18.+
cordova.system.library.5=com.google.firebase:firebase-core:17.+
cordova.system.library.6=com.google.firebase:firebase-messaging:19.+
cordova.system.library.7=com.google.firebase:firebase-config:18.+
cordova.system.library.8=com.google.firebase:firebase-perf:18.+
cordova.system.library.9=androidx.annotation:annotation:1.1.0
cordova.system.library.10=com.google.android.gms:play-services-location:16.+

In my case, changing compileSdkVersion = 29 and targetSdkVersion = 29 to compileSdkVersion = 31 and targetSdkVersion = 31 works without changing androidxCoreVersion = '1.2.0' to androidxCoreVersion = '1.6.0'

The problem is caused by newer version of androidx.core:core-ktx missing lStar.

To find the package causing the problem, I searched through all installed node_modules for core-ktx: and found implementation "androidx.core:core-ktx:+" in the react-native-camera-kit package.

I would like to lock this to core-ktx:1.6.0 to fix the build issue. Using patch-package that is straight forward (make sure you have a fresh package installation without build artifacts):

  • Change core-ktx:+ to core-ktx:1.6.0 in the build.gradle file, in my case node_modules/react-native-camera-kit/android/build.gradle
  • Run yarn patch-package <package to fix>, in my case yarn patch-package react-native-camera-kit
  • Rebuild for Android to check that it works
  • Commit patch

In my case, it was caused by the line in build.grale, classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0".

After I added a new empty activity to the project with Android Studio Arctic Fox 2020.3.1 Patch 4, Android Studio altered the build.gradle file

from: classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

to: classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"

While many of the solutions indicate to use

androidx.core:core:1.6.0

I discovered that in my project, one module was using version 1.7.0

After changing it to 1.6.0, this problem went away. So if you have multiple modules, make sure you check all of the build.gradle files that they are all using the same version.

Related