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>
Related
I've been getting familiar with Android Studio for the last couple of days and it has been stable for the most part , until I added the Material Design dependency and I got a whole bunch of errors when building the project.
I've been tinkering around with buildtools/sdk versions but nothing seems to work.
Here's my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "app.anuythe.com.apend"
minSdkVersion 24
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'])
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
}
Errors:
https://i.stack.imgur.com/OYWDg.png
I suggest you upgrade to AndroidX:
dependencies {
implementation
'com.google.android.material:material:1.1.0'
implementation 'androidx.appcompat.appcompat:1.1.0'
implementation
'androidx.constraintlayout.constraintlayout:1.1.3'
}
PS: the versions are not the latest though, just pointing u in the right direction.
Cheers!
I want to add the app:layout_behavior attribute in xml file but it not supported. Which library should I add in gradle file?
compile 'com.android.support:design:22.2.0
when I add this compile library android Studio gives error I have to androidx library to support that app:layout_behavior.
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.expensemanager"
minSdkVersion 16
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:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
implementation 'com.google.firebase:firebase-auth:19.0.0'
implementation 'com.google.firebase:firebase-database:19.1.0'
implementation 'com.google.firebase:firebase-functions:19.0.1'
implementation 'androidx.cardview:cardview:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
please help me what should i implement to support app:layout_behavior
Use the Material Components Library which is a drop-in replacement for Android's Design Support Library.
implementation 'com.google.android.material:material:1.1.0-beta02'
or the latest stable version:
implementation 'com.google.android.material:material:1.0.0'
I am learning to write android apps by watching some tutorials on youtube. I follow the tutorials and try to add the recyclerview in the xml file. When I click the download button next to the recyclerview, the following message is shown:
"This operation requires the library androidx.recyclerview:recyclerview:+.
Problem: Inconsistencies in the existing project dependencies found.
Version incompatibility between:
- androidx.appcompat:appcompat:1.1.0#aar
and:
- androidx.core:core-ktx:1.1.0#aar
With the dependency:
- androidx.annotation::1.1.0
versus:
- androidx.annotation::2.0.0
The project may not compile after adding this library.
Would you like to add it anyway?"
If I choose OK and go ahead, the preview screen becomes grey.
What should I do to solve the problem?
The same problem occurs when I want to add the cardview in the xml file.
thanks in advance!!!!
The build.gradle is below:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.smartherd.msgshareapp"
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.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Just build the project again and manually refresh the layout. :)
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.
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