android.support.v7.widget.CardView not being recognized - android

I'm trying to use older dependencies for my app and in the XML file it doesn't recognize the layout and it gives me an error. Moreover the build.gradle files compiles perfectly yet shows a red underline below the implementations of cardview and recyclerview.
Xml File:
Attached picture of what I need but yet isn't recognized.
https://i.stack.imgur.com/bZIbm.jpg
build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.testsuccess"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-database:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:21.+'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.firebaseui:firebase-ui-database:4.2.0'
}
I've even tried implementing
implementation 'com.android.support:cardview-v7'
implementation 'com.android.support:recyclerview-v7'
But it forces me to Migrate to Androidx libraries and doesn't allow me to use the old ones.
Note: the layout is an additional file in the project.

Add:
implementation 'androidx.cardview:cardview:1.0.0'
This will bring in androidx.cardview.widget.CardView, which is what your layout is looking to use.

If you want to use the old class names, you need to disable the androidx from gradle.properties file using
android.useAndroidX=false
android.enableJetifier=false
Which forces the androidx to be disabled.
OR
Dont want to disable androidx.
Then replace this line
from
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
to
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
This will work fine in AndroidX.

Related

How can I add cardview to my android studio project?

I've been having this problem for a long time.
ERROR: Failed to resolve: cardview
Affected Modules: app
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.self"
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
}
Add implementation 'com.google.android.material:material:1.1.0' to your dependencies
Navigate to the layout design part and select design oy now in the search (left side of page) search for card view. If that isn't downloaded you'll find a download symbol right next to it. Click on it and this will add the following dependency
com.google.android.material:material:1.0.0 and you're done.
You can add implementation "androidx.cardview:cardview:1.0.0" this dependency in your build.gradle (Module:app)
In your layout file:
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
</androidx.cardview.widget.CardView>

Unable to add layouts to an activity using Android Studio

Using Android Studio, in my activity's .xml I can't edit the layout in regards to which layout type the overall one is. The only way for me to change layouts is to copy-paste the layout code from somewhere on the internet and I've been doing it like that for the past month.
This is ridiculous. Why am I having this issue?
Drag and dropping a layout on to the activity inside of the designer does nothing.
Upon creating an empty activity of which the default layout is "ConstraintLayout", I can't do anything with that layout inside of the designer. I can only remove it by deleting the code from within the .xml view.
My build.gradle (Module: app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "hr.package.name.testsigninna"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:recyclerview-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
The problem is present in all projects I make.
I'm not sure but please check the gradle or it's version may be too old whether all the dependencies are working or not. Sync them and rebuild the project.

Unresolved reference: ActivityCompat in Android Kotlin

I am implementing OCR results in android using kotlin language by this tutorial
I am unable to solve this ActivityCompat error
import android.support.v4.app.ActivityCompat
My Gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.ocrofflinesample"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
// implementation 'androidx.support:appcompat-v7:'
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.gms:play-services-vision:15.0.1'
implementation "org.jetbrains.anko:anko:0.10.4"
// Logger
implementation 'com.orhanobut:logger:2.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
How to resolve this `ActivityCompat error`?
You have to use Androidx dependency. Change the android.support.v4.app.ActivityCompat to androidx.core.app.ActivityCompat
Check this out for pre-Androidx to Androidx dependencies mapping.
You might have either used AndroidX while creating project, or you have used AndroidX dependencies in non - androidX artifact.
Either you need to migrate it to androidX as suggested above.
Also, if you have used app:layout_scrollFlags in layouts, you
might wanna check out the scroll constants after refactor because
recently when I refactored, I didn't get any build error but when the
activity with scrollFlags loaded, it crashed and upon finding
out, it was a refactor issue due to that it was unable to change
constant names as per AndroidX.

Render error android studio failed to load appcompat action bar, even after matching library versions

apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.app.newzubair.yld"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support:support-v4:28.0.0-alpha3'
implementation 'com.android.support:support-media-compat:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.0'}
apply plugin: 'com.google.gms.google-services'
So this is my gradle build, now I have corrected the android support library versions(as the chosen solution on this community suggested) I still cannot see the changes I make in XML rendered onto the emulation.
This is the screenshot
com.android.support:appcompat-v7:28.0.0-alpha3 has few bugs
change
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
to
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
Add this line android:orientation="vertical" inside your LinearLayout tag

problems with 'com.android.support:appcompat-v7.27.1.1' in the gradle file

This is my dependencies file and there is an underlined red colored text on the compile 'com.android.support:appcompat-v7.27.1.1'
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.abc.mcaproject"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7.27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-database:11.6.0'
implementation 'com.google.firebase:firebase-messaging:11.6.0'
implementation 'com.google.firebase:firebase-auth:11.6.0'
implementation 'com.google.firebase:firebase-storage:11.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
This because of this I am having problems changing themes in the styles.xml
when you hover over the red line it may show you the image like this which I have attached below.
What it tells you is there is a conflict of the version in some libraries so it suggests us to add those. For my case first, it showed for CardView and then for Design. So I added to it. Below is the code for it.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.payumoney.sdkui:plug-n-play:1.2.0'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
so kindly add those it may be 2 or more than that.
Hope that helps.
In Android Studio 3.0 ,the compile configuration is now deprecated and should be replaced by implementation or api.
Just replace:
implementation 'com.android.support:appcompat-v7.27.1.1'
compile with implementation
testCompile with testImplementation.
debugCompile with debugImplementation.
androidTestCompile with androidTestImplementation.
compileOnly is still valid. It was added in 3.0 to replace provided and not compile.
for more information read this gradel doc
Reason of fail
You are using incompatible version of firebase with 27.1.1 support version.
Current version > 16.0.0 and you use 11.6.0.
Solution
Update your firebase dependencies versions. I suggest update target sdk version also.
Below is updated gradle as of date 1-10-2018, you can see firebase page to check latest version.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.abc.mcaproject"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7.28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-database:16.0.2'
implementation 'com.google.firebase:firebase-messaging:17.3.2'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-storage:16.0.2'
}
apply plugin: 'com.google.gms.google-services'
Suggestion
Migrate to androidx because Android will not update support libraries after version 28.0.0.
just goto-> files->project structures->app->flavors
change your min SDK version and target SDK version to "API 27:"
then go to properties and check that your compile SDK version has also changed to the above version which you selected.
This worked for me.

Categories

Resources