AppCompatActivity is not assignable to Activity - android

After a year of coding in android and everything working perfectly till yesterday. Today, I found something really strange after upgrading to gradle 3 alpha 2 and studio 3 build 2.
This is the declaration of one of the activities throwing error:
This is the activity code:
What is wrong?
EDIT
appcompat dependency:
compile 'com.android.support:appcompat-v7:23.2.1'

Maybe this will help:
In the app build.gradle, change compileSdkVersion and targetSdkVersion to 25.
Also upgrade the version of the appcompat library to 25.3.1:
compile 'com.android.support:appcompat-v7:25.3.1'
UPDATE 05/31/2017:
As #cricket_007 pointed out to me in comments, it isn't caused by a problem with the non-existence of AppCompatActivity, as I had theorized (in comments).
And while I have not been able to track it down, it looks like the lint checking is behaving differently or misbehaving on Android Studio 3 Preview, or in the 3.0.0 alpha2 version of Android Gradle Plugin, some build tools versions (or somewhere).
If your code is compiling ok (in spite of the "assignable" complaint appearing in AndroidManifest.xml) and you want to keep using Android Studio 3 Preview, maybe it's worth trying to suppress "AndroidDomInspection" on that activity tag for now:
<!--suppress AndroidDomInspection -->
<activity android:name=".admin.AdminChangeCoach">
. . .
</activity>
But, FWIW, I also agree with #cricket_007's earlier comment: I'm not using Android Studio 3 for production yet either.

As an alternative ways, you can simply change the class that you extended to Activity class instead of AppCompatActivity.

Related

Incorrect configuration. Please configure your build for VectorDrawableCompat with Gradle 7.0.2

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.

Android Studio: android.support.v7.widget.RecyclerView Error

I am currently having this error. I am using API 21 and I know some folks here suggested to upgrade it to API 22 base on previous questions but the tutorial(Slidenerd of Youtube) I am following is using API 21 and did not encountered any errors like this. Weird thing also because my RecyclerView in emulator is just working fine as expected in his tutorial and I don't why this error keeps popping up. Thanks !
It is not an error. Because the constructor is getting called while viewing the layout. Normally there are some operations which are going to be executed. To avoid this there is View.isInEditMode().
Normally you would use it like this
public Constructor(){
if(View.isInEditMode())
return;
}
If I understand your question correctly you are talking about the message the preview window of your layout is giving you?
You are probably using a version of recycler view that is newer than your compile version.
In you build.gradle file where you have added recyclerview to your dependencies you can try downgrading the version you are using
Change compile 'com.android.support:recyclerview-v7:22.2.1'
to compile 'com.android.support:recyclerview-v7:21.0.3' (or change to a 21.x.x version that suits your needs

The following classes could not be found: - android.support.design.widget.TextInputLayout

This is Tutorial which i am following.
Please help me out from this error. Rebuild is not solving the problem.
Does your build.gradle file contain the line below?
compile 'com.android.support:design:22.2.0'
You must include support libraries (like the ones below), yet this is sometimes not sufficient.
compile ("com.android.support:support-v4:23.3.0")
compile ("com.android.support:appcompat-v7:23.3.0")
compile ("com.android.support:support-annotations:23.3.0")
compile ("com.android.support:recyclerview-v7:23.3.0")
compile ("com.android.support:design:23.3.0")
Examine your layout in design view, and click on Show Exception
This answer will help if you have the following problem:
You need to use a Theme.AppCompat theme (or descendant) with the design library.
In your Manifest file, include in your application declaration
android:theme="#style/Theme.AppCompat"
Rebuild and your problem should be solved.
First things first :
If you are using the lastest sdk28 TextInputLayout is having some bug. At least mine did (date: 22 Sept 2018 ) NOT work.
To make it work the best way is to use slightly lower SDK for you target and compile SDK version. (I used sdk 27 and everything worked out fine then.)
To use TextInputLayout and then its features such as "floatinghinttext" you need to update your build.gradle(module.app) found in gradleScripts.
in dependencies add-
implementation 'com.android.support:design:25.0.0'
(if you get some error it must be of some latest version available, so use that instead of 25.0.0)
Note: The "compile" keyword is getting replaced by "implementation" for newer/all versions.
I am fairly new to android development, suggestions are welcomed. Please excuse if any mistakes committed.

Error after adding AppCompat v7 in Android Studio

After adding the appCompat v7 library I get the error that R cannot be resolved, which is apparently due to the fact that R now exists twice. I found an answer to that problem here : Build errors after adding fullscreen activity in Android Studio
However, I dont have or cant find the file attrs.xml in \src\main\res\values\attrs.xml. Is there any other solution to that problem or can someone give me a detailed description of how to do that in Android Studio?
Thank you very much!!!
Put this in your /app/build.gradle file :
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.android.support:appcompat-v7:18.0.0'
}
and make sure the version code (here 18.0.0) is not higher than the buildToolsVersion in the same file :
android {
compileSdkVersion 16
buildToolsVersion "18.0.0"
}
then rebuild your project. Hope that helps!
Oh and make sure you have the right buildTools installed via SDK Manager! Actual version is 21.0.2 I think.
I'm may be noob, but after several search i was able to add appcompat.v7 in android studio.
Initially i was comfortable with Eclipse after Dex Error 65535, my whole hard work was doomed i thought.
As Honey suggested you have to add both support.v4 or v13 and appcompat.v7 in build.gradle.
That's it. This simple solution not even covered in google docs ;). A simple reminder appcompat depends on v4 or v13.

Android Studio rendering problems

I'm using Android Studio 0.2.3 and when opened an activity layout normally, the preview should appear on the right side, so that I can switch between Text and Design mode, which should again show the preview of the layout.
But no preview is shown not on the right side neither when I'm in text mode nor in the design mode. I just get the error rendering problems...
When I compile everything and install the app on my device, it works without any errors. For developing and experimenting with the layout, it would still be nice if I could get the preview to work.
I have also tried to switch between different devices in the studio, but no success.
Does anyone know how solve this?
Change your android version on your designer preview into your current version depend on your Manifest. rendering problem caused your designer preview used higher API level than your current android API level.
Adjust with your current API Level. If the API level isn't in the list, you'll need to install it via the SDK Manager.
In new update android studio 2.2 facing rendering issue then follow this steps.
I fixed it - in styles.xml file I changed
"Theme.AppCompat.Light.DarkActionBar"
to
"Base.Theme.AppCompat.Light.DarkActionBar"
It's some kind of hack I came across a long time ago to solve similar rendering problems in previous Android Studio versions.
Open AndroidManifest.xml
Change:android:theme="#style/AppTheme"to something like:android:theme="#style/Theme.AppCompat.Light"
Hit "refresh" button in the "Previev" tab.
I was able to fix this in Android Studio 0.2.0 by changing API from API 18: Android 4.3 to API 17: Android 4.2.2
This is under the Android icon menu in the top right of the design window.
This was a solution from http://www.hankcs.com/program/mobiledev/idea-this-version-of-the-rendering-library-is-more-recent-than-your-version-of-intellij-idea-please-update-intellij-idea.html.This required a Google translation into English since it was in another language.
Hope it helps.
In the Latest Android Studio 3.1.3, Dependency:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
or
Even in latest by 27th of Aug 18 ie
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
facing similar issue
Change it to
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1
This will solve your problem of Preview.
UPDATE
Still, in beta01 there is a preview problem for latest appcompact v7 library
make the above change as changing it to alpha01 for solving rendering problem
When I set that android:autofillHints="" /> in .xml file, I met the issue, Android Studio rendering problems, so I set that android:autofillHints="testHint" />, this issue is gone.
I have solved the Problem by changing style.xml
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
this was an awesom solution.
it still happens in Android Studio 1.5.1. on Ubuntu and you can solve it simply changing a setting from Gradle:
1) on app/build.gradle dependencies change from:
compile 'com.android.support:design:23.2.0'
to:
compile 'com.android.support:design:23.1.0'
2) rebuild project
3) refresh view
Best regards,
/Angel
I had the same problem, current update, but rendering failed because I need to update.
Try changing the update version you are on. The default is Stable, but there are 3 more options, Canary being the newest and potentially least stable. I chose to check for updates from the Dev Channel, which is a little more stable than Canary build. It fixed the problem and seems to work fine.
To change the version, Check for Updates, then click the Updates link on the popup that says you already have the latest version.
In build.gradle below dependencies add:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "27.+"
}
}
}
}
This worked for me, I found it on stack, addressed as the "Theme Error solution":
Theme Error - how to fix?
Rendering didn't work for me too. I had <null> value on the right side of the android icon. I ran
sudo apt-get install gradle
I restarted Android studio then and <null> value changed to 23.
Voila, it renders now! :)
Just download minimum prefered SDK from SDK Manager, then build. Works for me.
Make sure your designer version and targetSdkVersion both is same.
Example : If your targetSdkVersion is 22 then change your designer version also 22, so this problem do not occur.
Best Solution is go to
File -> Sync Project With Gradle Files
I hope this helped
All you had to do is go to styles.xml file and replace your parent theme from
Theme.AppCompat.Light.DarkActionBar
to
Base.Theme.AppCompat.Light.DarkActionBar
Open your activity_main.xml .
Switch to Design view if you are in text view.
Look for the android version,with the android robo icon.
Change the android version.
Problem solved.
this issue is probably derived from the connection of the laptop to software products like AnyConnect. Killing the remote connection works for me.

Categories

Resources