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

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.

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.

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.

I did this for solving it in my Flutter application.
Open the android/app project
Search the text androidx.core:core-ktx:+ in all solutions. In most cases this is found in build.gradle file.
If you found this text in some dependency, change androidx.core:core-ktx:+ to androidx.core:core-ktx:1.6.0
Sync and run again
In my case, I had this problem with the audioplayers: ^0.17.3 dependency. The + sign was causing the error.

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.

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

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.

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"
}

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.

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

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!

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

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'
}
}

Add the following to your Project build.gradle:
buildscript {
ext {
androidXCore = "1.6.0"
}
}

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.

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

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

For Cordova
Uninstall cordova.plugins.diagnostic and cordova-plugin-androidx by running
cordova plugin remove cordova.plugins.diagnostic
cordova plugin remove cordova-plugin-androidx

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'

All you have to do is go in build.gradle and erase the entire line:
implementation "androidx.core:core-ktx:+"
super easy

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'
}
}

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.

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

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.

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

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

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'

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

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'
}
}

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

Use this::
buildscript {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
androidXCore = "1.6.0"
}
}

Related

Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'

I'm having a problem with running my android app:
Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'
That is caused by 1.7.0:
implementation 'com.google.android.material:material:1.7.0'
You better stick to 1.6.0 till they fix this
implementation 'com.google.android.material:material:1.6.0'
In your build.gradle file where "dependencies" section is paste this:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
in this section. And remove old strings with same text and other number versions. (in my case:
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
). Have worked for me.
source: https://github.com/facebook/react-native/issues/33926
Upgraded android gradle plugin to 7.2.2 and the problem is solved. Try updating Android Studio too
Rationale
To expand on the existing answers, the release notes for Material Components for Android 1.7.0 mentions that they have updated the minimum requirements for your project (emphasis mine):
New minimum requirements for your app's project:
Update to Android Gradle Plugin (AGP) version 7.2.0
Update to Gradle version 7.3.3
Update to Java 8 (version 1.8)
Update to Android Studio Chipmunk, version 2021.2.1
This is also mentioned in their (updated) Getting Started guide (again, emphasis mine):
5. Gradle, AGP, and Android Studio
When using MDC-Android version 1.7.0-alpha02 and above, you will need to make sure your project is built with the following minimum requirements, in order to support the latest build features such as XML macro:
Gradle version 7.3.3
Android Gradle Plugin (AGP) version 7.2.0
Android Studio Chipmunk, version 2021.2.1
Updating the Android Gradle Plugin
You can update the Android Gradle plugin as follows:
Gradle plugins DSL
The plugin declaration can be found in the top-level build.gradle/build.gradle.kts file:
plugins {
// Or "com.android.library"
id("com.android.application") version "7.2.2" apply false
}
Buildscript classpath
Update the AGP classpath dependency (usually in the top-level build.gradle/build.gradle.kts file):
classpath("com.android.tools.build:gradle:7.2.2")
update your build.gradle file as below:
classpath 'com.android.tools.build:gradle:7.2.1'
It will fix the issues, remember v7.3.x wont fix the issue, so stick to 7.2.1 as of now.
For Flutter User with this issue this is how you solve it::
Goto : build.gradle
change "classpath 'com.andriod.tools.build:gradle:5.6.0'"
to
"classpath 'com.andriod.tools.build:gradle:<latest version>'"
in my case :: classpath 'com.android.tools.build:gradle:7.2.1'
then goto :: android/gradle/wrapper/gradle-wrapper.properties
then change
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.3-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-<latest>-all.zip
in my case distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
In build.gradle(:app),
Updating, compileSdk and targetSdk to 33 helped me(from 32).
In order to get over with this. Upgrade to the latest gradle version as well as latest Android Studio.
I was also facing this issue and I followed these steps :
Upgraded Android Studio to Android Studio Dolphin | 2021.3.1 Patch 1
gradle version to 7.3.1 in project build.gradle
kotlin version to 1.7.20 in project build.gradle
targetSdkVersion and compileSdkVersion to 33
latest version of dependencies in app's build.gradle
And the project is perfectly working fine now.
I resolved it by replacing implementation 'androidx.recyclerview:recyclerview:1.2.1' instead of implementation 'com.google.android.material:material:1.7.0' in build.gradle(:app)
Upgraded android gradle plugin >= 7.1.0 and the problem is solved.
classpath "com.android.tools.build:gradle:7.1.0"
After wasting 2 hours and ruining my mood solution was simply upgrading your android studio version, most probably you are using an older version like Arctic fox or something like that, upgrade to dolphin or something higher. Hope it help, and yes in dolphin version it will give error of 30.0.3 but don't worry it gives you an attached link to install 30.0.0 SDK in console itself, so chill and keep developing.
first, in the gradle build file, change the implementation from 1.7.0 to 1.6.0
Next, open the colors file and change the color of the tag (#) which has 7 digits to a 6 digit tag. Because usually the default color of tags on Android Studio is sometimes 7 digits or 6 digits
I solved this by :
Adding in build.gradle:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
adding android:exported="true" in Manifest

Gradle build error of app after Android Studio 4.1 update

I have updated from Android Studio 4.0 to 4.1. After the update I cannot build my application anymore which worked fine before the update.
When I build the project I am getting the following exception:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compressDebugAssets'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CompressAssetsWorkAction
my\application\path\app\build\intermediates\merged_assets\debug\out
The folder my\application\path\app\build\intermediates\merged_assets\debug\out is empty.
What I tried to do:
Clean and rebuild the project
delete the .gradle and the build folder and clean an rebuild the project
invalidate and restart Android studio
Increased the heap size in gradle.properties to: org.gradle.jvmargs=-Xmx4096m
Increased the compileSdkVersion and targetSdkVersion
Installed and updated the buildToolsVersion from 30.0.0 to 30.0.2
Added multiDexEnabled true to my config
My gradle configuration looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-R'
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "my.application.id"
minSdkVersion 23
targetSdkVersion 29
versionCode 2
versionName "1.1"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url 'https://maven.google.com' }
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.navigation:navigation-fragment:2.3.1'
implementation 'androidx.navigation:navigation-ui:2.3.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.room:room-runtime:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'androidx.multidex:multidex:2.0.1'
}
Guys, I am out of ideas as I am no expert when it comes to gradle. Help would be most appreciated.
I found a temporary solution in downgrading my Android Studio version to 4.0.2.
Additionally, I changed the Android gradle plugin version to 4.0.2 and the gradle version to 6.1.1 which I had installed before. You can do this under File -> Project Structure -> Project.
Now I am able to run my application again. I am aware that this is only a temporary solution but at least I can work again on my application.
I will try to install Android Studio 4.2 Canary 15 the next days and check, if this works for me. I let you know.
This is what usually works for me every time i make an update, I hope it works for you.
Sometimes gradle build fails because, downloading some dependencies required by gradle for a successful build are missing and need to be downloaded. So make sure your computer is online.
-> Click on gradle (right side of your android studio), then toggle the highlighted button in the pic below.
Make sure its not highlighted, Cause if it is highlighted that means gradle is offline (has no access to internet)
Then rebuild project to download the missing gradle dependencies.
I hope you find this useful.
this solution may help. I had problems with this error showing up and I had no idea why. As it turns out, I save my android projects to a USB stick. The USB stick is formatted using PAL. I reformatted using NTFS and the problem has gone.
I had a similar problem this morning after updating my Android studio. In my case, previous projects run well but if I create a new project and attempt to run, I will get the said error message. I changed the Android Gradle plugin version to 4.0.2 and the Gradle version to 6.1.1 from the project structure dialog and I was able to run the app successfully afterward.
I have this problem when I try to build apk with capacitor Ionic in Android Studio. My solution was:
First change the Android Gradle plugin in build.gradle to classpath 'com.android.tools.build:gradle:4.0.2' and in gradle-wrapper.properties change Gradle version to distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip and press Sync Now.
When gradle sync is finish, close Android Studio Editor and go to project folder and inside android delete .idea and .gradle folders. Next you need to open PowerSheel in this location and run the code .\gradlew clean.
Finally, you can open the project with android studio using in vs npx cap open android or as you want, wait for sync gradle and then you can build your apk.
Changing the location my projects from a FAT32 formatted drive to an NTFS drive solved the problem for me.

Running "cordova build android" - unable to find attribute android:fontVariationSettings and android:ttcIndex

When I run cordova build android --buildConfig xxxx --release,
I get the following error:
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex
The strange thing is I use two macOS machines for the compilation, and I get this error only on one of them for the same code.
Here is the output of ./gradlew cdvPrintProps I get on the two machines:
:cdvPrintProps
cdvCompileSdkVersion=26
cdvBuildToolsVersion=27.0.3
cdvVersionCode=null
cdvMinSdkVersion=21
cdvBuildMultipleApks=true
cdvReleaseSigningPropertiesFile=release-signing.properties
cdvDebugSigningPropertiesFile=null
cdvBuildArch=null
computedVersionCode=152045989
computedArmv7VersionCode=1520459892
computedX86VersionCode=1520459894
Below is the list of plugins used:
$ cordova plugins list
cordova-custom-config 5.0.2 "cordova-custom-config"
cordova-fabric-plugin 1.1.10 "cordova-fabric-plugin"
cordova-open-native-settings 1.5.0 "Native settings"
cordova-plugin-app-event 1.2.1 "Application Events"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-console 1.1.0 "Console"
cordova-plugin-crosswalk-webview 2.4.0 "Crosswalk WebView Engine"
cordova-plugin-datepicker 0.9.2 "DatePicker"
cordova-plugin-device 2.0.1 "Device"
cordova-plugin-email 1.2.7 "EmailComposer"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-inappbrowser 1.7.2 "InAppBrowser"
cordova-plugin-network-information 1.3.4 "Network Information"
cordova-plugin-secure-storage 2.6.8 "SecureStorage"
cordova-plugin-splashscreen 4.1.0 "Splashscreen"
cordova-plugin-statusbar 2.4.1 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova.plugins.diagnostic 3.9.2 "Diagnostic"
de.appplant.cordova.plugin.local-notification 0.8.5 "LocalNotification"
ionic-plugin-keyboard 2.2.1 "Keyboard"
How can I fix this problem?
Just put following in build-extras.gradle
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
Google released the new version 28.0.0-alpha1 of com.android.support:support-v4 which is adding 2 new attributes(android:fontVariationSettings and android:ttcIndex).
Some of the plugins are using the latest android-support libraries which results in unwanted incompatibilities.
Option 1:
Install cordova-android-support-gradle-release plugin.
Well documented plugin which "aligns various versions of the Android Support libraries specified by other plugins to a specific version". Tested without any destructive behavior.
cordova plugin add cordova-android-support-gradle-release --fetch
Read the documentation for a full set of options: Readme
Option 2:
Add next code snippet in build.gradle under platforms/android
/**
IMPORTANT - Manually added
Problem: 8 March 2018 - Google released version support-v4:28.0.0-alpha1
which breaks the project with following error: unable to find attribute
android:fontVariationSettings and android:ttcIndex
Effect: Force a specific version of the library
*/
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:27.1.0'
}
Warning: code in build.gradle will be overwritten if you remove/add the Android platform. If you don't want to use the plugin for some reason or somehow is not working for you, instead create a hook and overwrite the file every time. Check 2nd comment here.
If the problem is persistent you may try:
cordova platform rm android
cordova platform add android
OR
Make sure you don't have a previous version of the app installed on the device you test because you'll receive an ambiguous error when it tries to downgrade the existing version: "INSTALL_FAILED_VERSION_DOWNGRADE" and "UnhandledPromiseRejectionWarning: Unhandled promise rejection"
The same error is happening to me. Apparently, a new version of the com.android.support:support-v4 library was released, and the plugin I'm using defines com.android.support:support-v4:+ as dependency in plugin.xml. The + sign means that it will get the latest version (28.0.0), which seems seems to be incompatible with other plugins.
I was able to build a development version by changing all the plugin dependencies from com.android.support:support-v4:+ to com.android.support:support-v4:27.1.0. Also, I executed ionic cordova platform remove android and ionic cordova platform add android. Hope it helps, at least for development.
I have just fixed this issue by going to the platform/android folder and edited the project.properties) file and replaced com.android.support:support-v4:+ with com.android.support:support-v4:27.1.0.
If you really just need a quick fix on that issue to make your build run, you may try adding the following lines into your platforms/android/build.gradle file:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
Anyhow, setting the version here is not a sustainable fix.
It's strange, but it works when I add the below lines with the same versions.
This is my related lines in the platforms/android/build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: "CordovaLib", configuration: "debug"))
releaseCompile(project(path: "CordovaLib", configuration: "release"))
compile "com.android.support:support-v4:26.+"
compile "com.android.support:appcompat-v7:26.+"
// SUB-PROJECT DEPENDENCIES END
}
// ADDED THESE LINES
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:26+'
}
In my project, the problem was occurred because of the 'cordova-plugin-crosswalk-webview' plugin.
I found the solution on Ionic Forum, which was the only solution that worked for me:
Run:
ionic cordova platform rm android
Run:
ionic cordova platform add android#8.0.0
Run:
ionic cordova plugin add cordova-plugin-androidx
Run:
ionic cordova plugin add cordova-plugin-androidx-adapter
Make sure your gradle.properties has:
cdvMinSdkVersion=19
Make sure your build.gradle has:
project.ext { defaultBuildToolsVersion="28.0.3" //String
defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
defaultTargetSdkVersion=28 //Integer - We ALWAYS target the latest by default
defaultCompileSdkVersion=28 //Integer - We ALWAYS compile with the latest by default }
Make sure your config.xml has:
<preference name="android-minSdkVersion" value="19" />
from:
https://forum.ionicframework.com/t/firebase-app-unable-to-compile-on-android-with-aapt-error/166564/7
which is also handled in the stackoverflow answer:
https://stackoverflow.com/a/56656680/839691
I have the same error but not in cordova build. A new version of the com.android.support:appcompat-v7 and dependencies.But the incompatible version is in the third package that dependent on com.android.support:appcompat-v7.So i can't fixed the third package with #avmatte's solution.
Use #Sai Teja's solution to find incompatible package:
gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath
Then fixed it with:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-compat:{the_same_version}'
force 'com.android.support:appcompat-v7:{the_same_version}'
force 'com.android.support:support-core-utils:{the_same_version}'
force 'com.android.support:support-core-ui:{the_same_version}'
force 'com.android.support:support-fragment:{the_same_version}'
force 'com.android.support:support-annotations:{the_same_version}'
...
}
}
Above code force the dependencies version.
I was facing the same error. Did a complete research in the plugin-directory for com.android.support:support-v4:+ and replaced it with a static version code.
For me, com.android.support:support-v4:23.4.0 worked just fine. There was no need to remove and re-add the android platform then.
Here's an easy way to fix it that will persist when the platform directory is rebuilt and there's no need to go through all your plugins to try and find a culprit. Create a file build-extras.gradle with these contents:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
Then create the file after_platform_add/010_copy_build_extras.js with the following contents:
#!/usr/bin/env node
var fs = require('fs');
var rootdir = process.argv[2];
var android_dir = `${rootdir}/platforms/android`;
var gradle_filename = 'build-extras.gradle';
var gradle_file = `${rootdir}/${gradle_filename}`;
if (fs.existsSync(android_dir) && fs.existsSync(gradle_file)) {
fs.createReadStream(gradle_file)
.pipe(fs.createWriteStream(`${android_dir}/${gradle_filename}`));
}
Now recreate the android platform and it will use the pinned support library.
Add the following lines to your platforms/android/build.gradle
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
if still having issue try running this command:
cordova plugin add cordova-android-support-gradle-release --fetch
Some of your libraries should be using
com.android.support:support-v4:+
Find which one that is, with
gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath
And add that library as a module if it is not using a specific version in it's latest update (Also raise an issue in that library! ;) )
Thanks to #avmatte!
EDIT: You can also request gradle to force the library version
ext {
supportVersion {latest_version_here}
} // In root project.gradle
configurations.all {
resolutionStrategy {
force "com.android.support:support-v4:$supportVersion"
}
}
I was having the same problem out of the blue yesterday. It started randomly, but from reading around, it looks like it is to do with an update as mentioned above by #cpro90. However, I tried and could not find where to make the necessary manual change.
Eventually I identified that the problem was being caused by my cordova-plugin-crosswalk-webview plugin. On GitHub, I found the issue on the plugin repro this morning, and it had over 520 views by lunch.
#UNUMObile suggested the following in the build.gradle file to force an earlier version globally:
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:24.0.0'
}
This worked immediately for me and may help others with other plugins that also have had their dependency on 'com.android.support:support-4:<28. The new version 28 seems to be the issue.
I hope this helps someone move forward.
Just some tips for Kotlin developer:
If you follow these answers here, you are sure you don't have support-v4 library in your project but you are still seeing this error, please take a look at the ktx library.
I just figure out that I am using the latest 1.0.0-alpha1 version for ktx library and this error show out; after I changed back to version 0.3, everything back to normal now.
In your build.gradle file add
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
And in your project.properties file change cordova.system.library.3 to cordova.system.library.3=com.android.support:support-v13:27.+.
For Phonegap Build users, as #catu mentionned in a comment, you can try this plugin which purpose is to prevent build failures caused by including different versions of the support libraries.
Just fix this issue by putting following lines of code in platforms/android/app/build.gradle file, just after buildscript {} block:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
I had same problem after installing the cordova-plugin-file-opener2 plugin. It resoved after doing:
Option 1: Install cordova-android-support-gradle-release plugin.
cordova plugin add cordova-android-support-gradle-release --fetch
Another aproach with same solution is create a hook. It's persistent (after platform reinstall), you can commit it and it don't require re-adding platform.
%project%\scripts\android\android-support-version.js
#!/usr/bin/env node
var fs = require('fs');
function replace_strings_in_file(filename, replacementsObject) {
if (fs.existsSync(filename)) {
var data = fs.readFileSync(filename, 'utf8');
Object.keys(replacementsObject).forEach(function (to_replace) {
var replace_with = replacementsObject[to_replace];
data = data.replace(to_replace, replace_with);
});
console.log(data);
fs.writeFileSync(filename, data, 'utf8');
} else {
console.log('file not found');
}
}
module.exports = function (context) {
var rootdir = process.argv[2];
if (rootdir) {
replace_strings_in_file("platforms/android/project.properties", {'com.android.support:support-v4:+': 'com.android.support:support-v4:27.1.0'});
console.log('com.android.support version fix');
}
};
Init hook in config
%project%\config.xml
...
<platform name="android">
<hook src="scripts/android/android-support-version.js" type="before_build" />
...
Install fs dependency to your project:
npm i fs --save-dev
Run build:
cordova build android
SUPER SIMPLE AND CORRECT WAY OF SOLVING IT!
Just update the sdk and add the latest 2 version of android... and restart the computer! Done...
Now we have time to talk about cars and sports...
I had the same problem, and none of the given solutions worked for me. Installing the latest version of Android SDK Build-tools (27.0.3) resolved my problem.
Solution link
This is due to compat plugin.
Remove that plugin if you have older version (less than 1.2.0) and set cordova-android#6.3.0
cordova plugin rm cordova-plugin-compat --force
cordova plugin add cordova-plugin-compat#1.2.0
cordova platform rm android
ionic cordova platform add android#6.3.0
Working at my case. Thanks :)
updates to #Brad Pitcher's answer:
hooks/copy_build_extras.js
#!/usr/bin/env node
var fs = require('fs');
module.exports = function (context) {
var rootdir = context.opts.projectRoot;
var android_dir = `${rootdir}/platforms/android`;
var gradle_filename = 'build-extras.gradle';
var gradle_file = `${rootdir}/${gradle_filename}`;
if (fs.existsSync(android_dir) && fs.existsSync(gradle_file)) {
fs.createReadStream(gradle_file)
.pipe(fs.createWriteStream(`${android_dir}/${gradle_filename}`));
}
};
config.xml
<platform name="android">
<allow-intent href="market:*" />
<hook src="hooks/copy_build_extras.js" type="before_build" />
</platform>
build-extras.gradle in the root dir
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
I was running into this issue with react native and it was caused by the following lines in my android/app/build.gradle:
implementation ("com.google.android.gms:play-services-base:+") {
force = true;
}
implementation ("com.google.android.gms:play-services-maps:+") {
force = true;
}
etc...
Apparently this + resolved to a new 17.0.0 version which broke my build.
Changing the + to 16.0.0 (or 16.0.1 for play-services-base) solved my issue
This problem had been killing me for a week.
Ultimately I ended up on android#6.4.0
I altered android/project.properties by changing
#cordova.system.library.3=com.google.android.gms:play-services-analytics:+
cordova.system.library.3=com.google.android.gms:play-services-analytics:15+
That change finally got me out of the ttcIndex error message pit of darkness.
Then I got this error
com.android.builder.dexing.DexArchiveBuilderException:
com.android.builder.dexing.DexArchiveBuilderException
The error was apparently due to a Java version issue. I then altered android/build.gradle with the following change
compileOptions {
#sourceCompatibility JavaVersion.VERSION_1_6
#targetCompatibility JavaVersion.VERSION_1_6
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Also note I do have the cordova-android-support-gradle-release plugin installed, but have no idea if I need it.
It's a duplicate entry in values.xml in a folder called support-compat-28.0.0-alpha1.aar.
You'll find this file on Windows at \users\YOURUSERID\.gradle\caches\transforms-1\files-1.1
Once inside that folder you have to go some levels deeper to values.xml.
In that file, search for an element <declare-styleable name="FontFamilyFont>.
In that element, remove the FOUR lines with android: in it.
After I made that change I can build again without errors.

Getting "package android.support.multidex does not exist" after upgrading to Android Studio 2.3

I updated from Android Studio 2.2.3 to Android Studio 2.3 yesterday, and I ran into the following two problems:
Upon updating, Gradle 3.2 was installed by default, but syncing my
project would not work and I kept getting an error saying "Gradle 3.3
is required". Using the default Gradle wrapper doesn't work. The only way to fix this was to download Gradle 3.3
manually and point to the directory in build settings.
On running my project, I kept getting a string of errors involving my
BaseApplication class which extends MultiDexApplication. The
error goes something like this:
Error:(19, 62) error: package android.support.multidex does not exist
I am unable to resolve this error. I have buildToolsVersion '25.0.2', and my project compiled and ran properly before upgrading to Android Studio 2.3. Can anyone help me with this problem?
I have passed the building. my solution is that adding explicit dependencies in build.gradle.
compile 'com.android.support:multidex:1.0.1'
The solution to this problem is to add the following:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
in your build.gradle file.
This was not required prior to Gradle 3.3. This problem occurs only for apps that support Android versions below Lollipop (API level 21).
References:
1. Multidex support prior to Android 5.0.
Replace import android.support.multidex.MultiDexApplication; with
import androidx.multidex.MultiDexApplication;
what works for me is adding to your (app) build.gradle
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
}
In addition to:
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}
It is necessary to add this:
defaultConfig {
...
multiDexEnabled true
}

Cannot resolve symbol 'Theme' in styles.xml (Android Studio)

Since today, Android Studio can't find the AppCompat themes in styles.xml, but for example AppCompatActivity in code does get recognized. My Android Studio version is 2.2.2, Build #AI-145.3360264
I already tried upgrading to the latest build tools, compile sdk (25) version etc. but it didn't fix the problem.
At the moment I have installed the following (from sdk manager):
android api: 19 and 23
sdk platform tools: 25.0.1
sdk tools: 25.2.3
build-tools: 23.0.2 and 25.0.1
support repository: 40
google repository: 39
and a few others, that shouldn't be necessary to list here.
build.gradle of app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '25.0.1'
defaultConfig {
applicationId "xxx.xxxxxxxx.xxxxxxxxx" //not the real applicationId
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/RootTools.jar')
compile 'com.android.support:support-v4:23.+'
compile 'com.android.support:support-v13:23.+'
compile 'com.android.support:appcompat-v7:23.+'
compile 'com.android.support:design:23.+'
compile 'com.android.support:cardview-v7:23.+'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'de.hdodenhof:circleimageview:2.1.0'
}
Another solution that worked for me with Android Studio 3.1.2:
delete these from build.gradle if you have them:
'com.android.support:appcompat-v7:27.1.1'
'com.android.support:design:27.1.1'
then sync,
then undo delete,
then sync again.
I encountered this after updating to Android Studio 3.1.
None of the other answers listed here worked for me, however when I switched my appcompat support lib version to the latest 28.0.0-alpha1 then back to 27.1.0 that it was on before, it worked.
Seems the new version of Android Studio lost connection to where the library was synced to and just needed to have it reset.
No need to change anything.
Just press small button on top "Sync Project with Gradle Files"
EDIT: As #Alexey noted, bug still appears in Android Studio v3.1.4
This worked for me:
Click File > Close Project
Reopen the project from Studio's dialog.
That's because of feature called "build cache" that is enabled by default in build Android Plugin since 2.3.0.
It creates files in build cache outside of project folder (in my case -- in \Users\%username%\.android\build-cache)
Theese files are intended to be common between your projects.
And then Android Studio is unable to navigate in theese files.
That's all.
If you want to disable Build Cache, add android.enableBuildCache=false to gradle.properties file. Then restart Android Studio.
more info here:
https://developer.android.com/studio/build/build-cache.html#disable_build_cache
I have had the same problem. The only solution that worked for me was to manually delete the support libraries in file system and sync the project to let Android Studio download them again.
Steps:
Go to your project folder in File system
Go to .idea\libraries
Delete all the Gradle__com_android_support_****.xml files
Open Android Studio
Select File > Sync with File System
Once that is done, Select File > Sync Project with Gradle Files
Build Project
And now your error should be gone!!!
you can hit file -> invalidate Caches / Restart ... if it doesn't fix the issue you can close the project (file-> close project) and import it (file -> new -> import project.
I switched support lib to version 27.1.1 and problem has been solved. Seems like some bug in 27.1.0
I went through the same problem when I upgraded to alpha-2.
I looked at this link: http://tools.android.com/recent, but the only thing that worked well was:
Change this:
Classpath 'com.android.tools.build:gradle:2.3.0-alpha2'
For this:
Classpath 'com.android.tools.build:gradle:2.2.3'
In your build.gradle (Project)
Only this worked for me
Close project (File> Close Project)
Import / Re-Open project again (NOT from Recent)
Error should be resolved now.
If that fails, try below-
Open build.gradle, remove appcompact-v7 dependency and sync project.
Add appcompact-v7 dependency and sync.
I encountered same problem like this.Just the difference is I was using Studio 2.2.3. This is what solved my problem:
In my project level gradle I had:
classpath 'com.android.tools.build:gradle:2.3.0-alpha2' (which was a result of updating studio)
which I replaced with:
classpath 'com.android.tools.build:gradle:2.2.3'
I think you should look for a compatible classpath for your gradle configuration.
I was having the same issue after linking Firebase to my app. Updating the build.gradle in the app module did the trick, updated to:
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-database:11.8.0'
I had also the same problem when I upgraded my android studio from 2.2.2 to 2.3 Canary Version.
Although the new beta version of 2.3 is released yet it is using the gradle plugin of 2.2.3 which is of stable version.
So just change the classpath dependency in buildscript of build.gradle project level from alpha to 2.2.3 and sync it. It'll resolve the issue or change to the more appropriate version with respect to your channel version.
More on gradle watch this Gradle Recipes for android Ken Kousen - Gradle Summit 2016
https://www.youtube.com/watch?v=4L6wHTVmxGA
In newer versions of Android Studio, we are asked to use 'AppCompat'. Some users uncheck that and still use the Theme.AppCompat. That makes up this error. Same happened with me.
Solution is to add this line in your build.gradle (app).
compile 'com.android.support:appcompat-v7:26.1.0'
#Daniel Wilson made a comment in one of the answers that solved this issue for me. I wanted to add add as an answer to draw more attention to this solution.
Updating compileSdkVersion and targetSdkVersion from 26 to 27 (and then of course updating the dependencies) eliminated the errors for me.
Mine was fixed by deleting the .gradle file from the folder and re-importing the project in Android Studio
I also faced the problem with Android Studio 3.1 , syncing does not help me.
Then I switched back to
`'com.android.support:design:27.1.0'` from : `'com.android.support:design:27.1.1'`
and added android.enableBuildCache=false to gradle.properties to disable build cache
This is weird, I encounter this problem as below:
Android Studio is 3.1.2
support lib version is 27.0.0
I solve this by below:
change support lib version to 27.1.0, and "Sync Project with Gradle Files", then this error disappear
change support lib version to 27.0.0,and "Sync Project with Gradle Files", then this error not appear again
Deleted .idea and .gradle from project folder.
Then sync with gradle files, it worked.
I ran into the same problem when updating the Android Studio software.
What I did was this:
Go to the Gradle Settings as follows (this path is for Mac, but should be similar on Windows):
Android Studio -> Preferences -> Build, Execution, Deployment ->
Gradle.
Then pick "Use default gradle wrapper (recommended)".
If you already have that option chosen then your problem must lie somewhere else.
I changed my gradle version from
classpath 'com.android.tools.build:gradle:2.3.0'
to
classpath 'com.android.tools.build:gradle:2.2.3'
and it works now!
In Android Studio 3.1.3, the simple work around:
"Sync Project with Gradle Files"
If none of these methods mentioned by other contributors does not work for you..
Then please simply ignore this...
Even flutter officials also said to ignore these errors..
Caution*** Only ignore after trying all the methods.If above methods solve your errors then fine otherwise you can ignore these..
This type of errors happen after installing latest version of flutter sdk,gradle ,android studio and other plugins -packages
If you are using latest version then you have to ignore these errors.

Categories

Resources