My app, which was working before, suddenly started crashing in my LaunchActivity with: Please configure your build for VectorDrawableCompat. This is happening with Gradle 7.0.2, which doesn't make sense since other posts regarding this issue are from 3 years ago and recommend updating to gradle 2.0+ (which is much older) and also using the latest android support library (which is a non-issue now with androidx). They also recommend setting vectorDrawables.useSupportLibrary = true which has already been the case in my app. So those posts weren't relevant to my issue.
minSdkVersion 21
targetSdkVersion 31
vectorDrawables.useSupportLibrary = true
classpath 'com.android.tools.build:gradle:7.0.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
Oddly this started happening on my master after I switched to a different branch and then returned to my master branch after a month. However, the master branch shouldn't have changed at all and it must have been working before, because I cut a production release from it that previous month, and the production release wasn't crashing.
Caused by: java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat.
at androidx.appcompat.widget.ResourceManagerInternal.checkVectorDrawableSetup(ResourceManagerInternal.java:495)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:140)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:480)
at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:93)
at androidx.appcompat.app.AppCompatDelegateImpl.attachToWindow(AppCompatDelegateImpl.java:797)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureWindow(AppCompatDelegateImpl.java:773)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreate(AppCompatDelegateImpl.java:501)
at androidx.appcompat.app.AppCompatActivity$2.onContextAvailable(AppCompatActivity.java:131)
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:297)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
at com.somewearlabs.sw.ui.LaunchActivity.onCreate(LaunchActivity.kt:14)
at android.app.Activity.performCreate(Activity.java:7963)
at android.app.Activity.performCreate(Activity.java:7952)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
I finally fixed the issue. When I was inspecting the crash in Android Studio, clicking on the file/line number link (eg. "ResourceManagerInternal.java:495") opened up two options for the class, one in appcompat library version 1.2.0 and also 1.3.0. There must have been two versions used in my dependencies, even though in the build.gradle files for all of my projects explicitly stated androidx.appcompat:appcompat:1.2.0. Using a breakpoint showed that the line in 1.3.0 was getting called when launching the app.
Then I did File > Invalidate Caches and Restart.
I thought that ensuring that only one version of appcompat being used in the project might fix things, so I switched all the build.gradle files from using androidx.appcompat:appcompat 1.2.0 to 1.3.0. After resyncing/building, the crash went away. I don't know why this crash started happening in the first place - if anyone could shed some light on this - but I needed to update the appcompat dependency anyway so it worked out.
Was trying to include androidx.biometric:biometric:1.0.0-alpha03 as one of my android project dependencies, but gradle sync throws this error:
Error: Resource type cannot be an empty string (at
'strokeColor' with value '?android:/attr/colorAccent').
The file raising the red flag is:
app/build/intermediates/data-binding-layout-out/debug/drawable-v23/fingerprint_dialog_error_to_fp.xml,
Some other info that could be relevant:
compileSDK: 28
minSDK: 21
targetSDK: 28
Please note that I have not done any other migration to androidx, and I am still using an old gradle plugin and gradle itself.
Any help is really appreciated.
UPDATE
It seems like android:/attr/colorAccent should have been android:attr/colorAccent instead? Is that it?
I've used xwalk project in mine for a while now.
However, during the last round of library version upgrades, gradle doesn't like xwalk any more. Simply including it into my project
compile 'org.xwalk:xwalk_core_library:19.49.514.5'
will produce the following error on my dimens.xml:
error: resource android:attr/fontStyle not found.
error: resource android:attr/font not found.
error: resource android:attr/fontWeight not found.
dimens.xml:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
The conflicting attributes are actually referenced in app/build/intermediates/incremental/mergeDeployDebugResources/merged.dir/values/values.xml.
Initially I paid this no attention because I needed to develop some new functionality, but now it's time to publish and I need to make my "publish" flavor working again. The ONLY difference between gradle compiling or not being inclusion of xwalk into my project.
To make matters worse, I also upgraded Android Studio to version 3 and now I'm stuck not being able to revert my repository to something before the breaking change so that I could hunt for the issue.
I googled this a lot but it seems I'm the only one messing this up, so I'd appreciate any pointers on what I might be doing wrong.
Reverting xwalk version to an older one does not help. I'm currently using the latest version which still works on Android 4.0 (project requirement).
How can I fix this?
Edit: stupid me!!!
I didn't revert to OLD ENOUGH version of xwalk. reverting to 15.44.384.13 removes the problem.
The issue is that the attributes in question are only supported from API 16 forward and I must also work with 14 --> Even upping minSdkVersion to 16 doesn't solve the issue.
Edit2: disabling aapt2 does not help: the same errors are reported with aapt1.
Downgrading build tools from 26.0.2 to 25.0.2 does not help.
Edit3: Increasing compileSdkVersion & targetSdkVersion to 26 solves the problem. I have 22 normally because of Marshmallow permissions system. Note that it MUST be at least 26. Even 25 still produces the error.
I am allowed to leave it at 22 in the libraries I'm using, but not the main app project using xwalk.
Open build.gradle and put this at the end of the file:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
Running "cordova build android" - unable to find attribute android:fontVariationSettings and android:ttcIndex
I am getting the error: "Ambiguous method call" on initializing Toolbar using Android Studio 3.0 RC1. I have extended my Activity with AppCompatActivity and compiling my application using 'compileSdkVersion 26'.
Attaching a screenshot of the error.
If you recently updated your project to API, Try doing
File -> Invalidate Caches / Restart
then
File -> Sync Project with Gradle Files
this resolve for me.
Upgrade to appcompat 27 solved this for me
For me, it was the compileSdkVersion which was different than the support libraries used
You have
import android.support.v7.app.AppCompatActivity
import android.app.Activity
both in your code.
Remove import android.app.Activity as I can see, it's not required for you.
For me changing build tool version to 27.0.2 worked, given that all your other dependencies are API 27 as well.
buildToolsVersion '27.0.2'
I have recently upgraded to build tools version 27.0.2 and faced the same problem. But noticed that I had the compileSdk version set to 25. Changing compileSdk to 27 resolved the issue.
"File - Invalidate Caches / Restart" Solved my problem.
For me none of the given solutions worked, however I had this issue because I had both 25 and 27 android sdk installed on my computer. As soon as I removed the sdk 25, the problem disappeared.
This can suddenly appear when running a code analyzer like FindBugs-IDEA. A quick way to clear the warning is to temporarily change the buildToolsVersion in your app/build.gradle then change it back again.
For example, follow these steps:
Open your app/build.gradle file.
Change buildToolsVersion to '26.0.1' then sync project (press the 'Sync Now' button when it appears at the top)
Change the buildToolsVersion back to whatever you had before.
Press the 'Sync Now' button
This should clear the error.
Maybe you have difference between compileSdkVersion and targetSdkVersion
I ran into the same issue with Android Studio 3.0.0 build 171.4408382. Building via Gradle on the command line worked just fine, but the IDE presented me with the above mentioned error. I have tried to use API level 26 with appcompat v26.1.0 and API level 27 with appcompat v27.0.1, but neither combination worked.
My "solution" was to downgrade compileSdkVersion and targetSdkVersion to API level 25 and the appcompat library to version 25.4.0.
For all of the mentioned version combinations I used Gradle plugin v3.0.0 and the Android build tool v27.0.1.
In my case, I removed the constraint layout dependency in the build.gradle (app) file and it solved the issue.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.1.0'
//implementation 'com.android.support.constraint:constraint-layout:2.0.4'
}
if answers does not resolve your problem , you can reset your android studio.
I solved with reset my android studio.
For reset: https://stackoverflow.com/a/19397632/3129822
First make sure that you have no transitive dependencies that are using older support libraries. Run the following command and make sure that no older support libraries are in use.
gradlew :app:dependencies
Make sure that your gradle file is updated with latest dependencies. eg: compileSdkVersion 27, targetSdkVersion 27, buildToolsVersion 27.0.3. etc. It would also benefit to make sure that non of your app flavors have been using a custom targetSdkVersion.
Ctrl + click on the findViewById method. It will show you the 2(perhaps more?) conflicting methods. In my case the conflict was between the findViewById method from API 23 and API 27. Therefore I had to remove the SDK and sources for Android version 23. Once I removed it and did Invalidate Caches/Restart it solved my problem.
My compileSDK version was lower than the targetSDK version so all I had to do was match them and sync project and the error was resolved.
Removing "Android Fast Networking" library solved my problem
I've had the same issue
Mine was related to the compileSdkVersion number from build.gradle app.
Changed to the latest and it worked for me.
Upgrading your targetSdkVersion or buildToolsVersion might resolve the problem.
No need to Invalidate Caches / Restart if this is a new project.
I was working with a new project and in gradle files did not have version numbers set in them, there was "N" across minsdkversion and targetsdkversion, changing to desired sdk version solved the problem
Upgrading both appcompat to 27 and compleSdkVersion to 30 works for me.Just upgrade those in gradle build.
Just upgrade your minSdkVersion 26 Its works for me.
When we create a Android project with minimum SDK lower than 16 and after that we want to add new activity using 'New/Activity/Gallery' we see the indication 'Selected activity templates has minimum SDK level of 16'. So we need to modify 'minSdkVersion' in build.gradle file which leads us to 'Sync Now' process.
If we must build and maintain an app with min SDK lower then 16, we have to change 'constraint layout' to another layout. However when we do this the constraint layout dependency still remains in the dependencies section in the 'build.gradle' file. This caused me the error.
In summary, this is applicable when we need to build a android project with minimum SDK version lower than 16.
When we add a new activity, we change the minSdkVersion in the build.gradle above '16' then click of 'Sync Now'. After that we can choose one of activity template and create a new activity.
Now we change 'constraint layout' in the xml file corresponds to the new activity we created to for example 'linear layout' or 'relative layout'
At this point we make sure delete the dependency which refers to constraint layout in the 'build.gradle' and then click the 'Sync Now' again.
I think the best practice to avoid this error message is to make Android project with minimum SDK 16 and above.
These steps worked for me on Android Studio for Mac (Arctic Fox v11):
In 'build.gradle' file (for module), change appcompat implementation version to something invalid (e.g. Change 'com.android.support:appcompat-v7:25.1.0' to 'com.android.support:appcompat-v7:25')
Click 'Gradle sync now' and let it finish. This should generate lots of errors
Correct the verison back to original (e.g. 'com.android.support:appcompat-v7:25.1.0'). Click 'Gradle sync now' and let it finish
Original issue with findViewId should disappear
We're dropping support for Android 2.3 (API level 9) devices because most of our users have a newer Android version on their phones. I've updated the minimum SDK version to api level 14.
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
}
}
However I'm still able to install the app on Android 2.3 devices manually (not by store). Is this expected behavior or am I doing something wrong? I couldn't find the answer somewhere else.
Another strange issue is that Lint doesn't detect the correct api level.
listView.setFastScrollAlwaysVisible(true);
This results in the warning: Call requires api level 11 (current min is 9).
However my current minimum is now 14. So this indicates to me that i did something wrong. I tried cleaning and rebuilding the project, restarting Android Studio. It all didn't work.
Can anyone help me out?
Edit
Based on Sufians comment I started fiddling around with my gradle files and I came to the following solution. However some questions still remain.
My project structure looks like this:
android.gradle (top-level build file which contains SDK versions)
main module (contains base code for other modules)
build.gradle (apply from: '../android.gradle')
sub module A (module specific changes)
build.gradle (has dependency on main module)
sub module B (module specific changes)
build.gradle (has dependency on main module)
I have a top-level build file android.gradle which contains the SDK versions. My modules then include the build file by apply from: '../android.gradle'. If I put the minSdkVersion directly in de main module the warnings disappear. Is that the way it should be? or do I need to set an minSdkVersion for every submodule? Or is there another way so that the SDK versions can stay within the android.gradle file?
Ok... I finally realized that there is nothing wrong in my project structure. The only thing I needed to do was press the little 'Sync Project with Gradle Files' button. After that all errors disappear.
Also I concluded that it's possible to install unsupported apps manually.
However the Google Play Store should prevent users from installing or updating the app.
i have personally never developed anything for android but when installing apps the device has never complained when installing an .apk that wasn't supported by the OS version.
even when the store said it wasn't supported i'm always able to install it as a .apk so i think it can't really be blocked.
Yes, you can install the app manually on your device as long the minimum API level specified in your manifest is less than your device's API level.
When you upload your app to the store, the store will not show your app to users with devices having Android version less than the min API level specified (API level 9 in your case).
As for the Lint warnings, make sure that the minimum/maximum SDK versions in your manifest file match those specified in the build.gradle file.
and you can also make sure that new APIs are not executed on older API levels by checking the OS version in the code.
http://developer.android.com/reference/android/os/Build.VERSION.html
If I put the minSdkVersion directly in de main module the warnings
disappear. Is that the way it should be?
Your main module's minimum and target SDKs (i.e inside the build.gradle of the module) will be that of your application.
The project's build.gradle should not contain any of this information.
or do I need to set an
minSdkVersion for every submodule? Or is there another way so that the
SDK versions can stay within the android.gradle file?
Each module defines its own minimum SDK. If you're using a third party module/library, you better not change it, unless you know what you're doing.