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.