Cannot resolve import android.support.v7.widget.RecyclerView; [duplicate] - android

This question already has answers here:
Android Studio keeps refusing to resolve com.android.support:appcompat-v7:29.0.1
(6 answers)
Closed 3 years ago.
I need to create a recyclerview in Android Studio. I don't know why it keeps saying that it cannot resolve symbol recyclerview. I have done all the step according to those website tutorial.
My app gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:appcompat-v7:29.1.1'
//card view
implementation 'com.android.support:cardview-v7:29.1.1'
//recyclerView
implementation 'com.android.support:recyclerview-v7:29.1.1'
//picasso library to retrive images
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.firebase:firebase-storage:18.0.0'
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.firebase:firebase-database:18.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
apply plugin: 'com.google.gms.google-services'
}
May I know what's wrong with my code in the gradle file? Thanks in advance.
Here is my error report in logcat:

you are trying to access the wrong package.
try androidx.recyclerview instead of the legacy android.support.v7.widget.RecyclerView;
you should replace all the com.android.support.* dependencies, and replace with the androidx equivalent. (currently, you have a mix of both androidx and the legacy android.support dependencies)
https://developer.android.com/jetpack/androidx/releases/recyclerview
you can try using the Refactor> Migrate to AndroidX option on Android Studio for the auto fix

replace you recyclerview library with this -> androidx.recyclerview:recyclerview:1.0.0
as you are using the androidx, but your recycler view's library is still in support library format
to get proper migration information do refer to this -> https://developer.android.com/jetpack/androidx/migrate

Related

how to fix ERROR: Failed to resolve: com.google.sceneform.ux:sceneform-ux:1.6.0?

actually i'm still a beginer on android studio. i tried using the default android 4.4 but when i add some implementation on the build.gradle the notification says failed to resolve: com.google.sceneform.ux:sceneform-ux:1.6.0. i've been trying some advice and some tutorial but still can't resolve the problem.
Here is the code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.arcraw"
minSdkVersion 19
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'com.google.sceneform.ux:sceneform-ux:1.6.0'
implementation'com.karumi:dexter:6.0.1'
}
Based on Sceneform overview, you should change the line in gradle file from
implementation'com.google.sceneform.ux:sceneform-ux:1.6.0'
to
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.6.0'
Update: The latest version is 1.14.0, just in case you want to use it
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.14.0'
Hi this issue is fixed in 1.9.0 version or you can use latest version 1.14.0
try
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.14.0
As in [1]: https://github.com/google-ar/sceneform-android-sdk
you can see that google abounded sceneform android sdk
and the library is archived as they said : This repository has been archived and is no longer maintained.
status: inactive

how to solve the problem of "Inconsistencies in the existing project dependencies found"?

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

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.

Error while importing Snackbar

I am trying to import Snackbar using below command. But getting error Cannot Resolve symbol Snackbar. What is the possible issue here? I tried adding "android.support.design" dependency but didn't work.
import android.support.design.widget.Snackbar
My build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "in.anamika.anamika"
minSdkVersion 15
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'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.9.7'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.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'
Snackbar belongs to Maven artifact com.android.support:design:27.1.1
You need to add dependency of design library
add below dependency in your build.gradle
implementation 'com.android.support:design:27.1.1'
Than Clean - Re-Build - Run your project
If you are migrating to androidx then use
com.google.android.material.R.id.snackbar_text
instead of
android.support.design.R.id.snackbar_text
Don't miss to import import com.google.android.material.snackbar.Snackbar;
Also implement implementation "com.google.android.material:material:1.2.0-alpha02"
You are missing dependency for design library in your build.gralde. Update it as follows:
dependencies {
...
implementation 'com.android.support:design:27.1.1'
...
}
After updating the file, click Sync Now at top right corner. Ensure you have internet connection so that dependencies can be downloaded.
If you still face issues after that, then clean and rebuild your project.
designYou need to add in dependencies in your build.gradle file.
implementation 'com.android.support:design:27.1.1'
And Sync your project.
I got error when I tried to import the Snackbar library
implementation 'com.android.support:design:27.1.1'
and I received new error saying that the support library should be the same version as the compileSDKVersion version, so I changed the implementation to
implementation 'com.android.support:design:28.0.0'
it fixed the error and I was able to use the Snackbar.

I'm trying to upgrade Android old library to androidx (Android + Kotlin)

but when I build it gives me an error
recently android updated for kotlin
and my android gradle vesion is 3.1.2
and kotlin version is 1.2.41
android studio 3.1.2
i'm targeting android p
this is latest version so i can't find more documentation on this problem and
please help me to find out this problem
android issues
Program type already present: android.support.v4.media.MediaBrowserCompat$ConnectionCallback$StubApi21
build.gradle(app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 'android-P'
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.xxxxxxx.xx"
minSdkVersion 18
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.anko:anko-commons:0.10.4'
implementation 'androidx.core:core-ktx:1.0.0-alpha1'
implementation "androidx.appcompat:appcompat:1.0.0-alpha1"
implementation "androidx.legacy:legacy-support-v4:1.0.0-alpha1"
implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
implementation "com.google.android.material:material:1.0.0-alpha1"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
//firebase massaging
implementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation 'com.google.firebase:firebase-core:15.0.2'
def lifecycle_version = "2.0.0-alpha1"
def room_version = "2.0.0-alpha1"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
// room database persistent
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
// optional - Test helpers for LiveData
testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
//data binding
//kapt 'com.android.databinding:compiler:3.1.2'
}
apply plugin: 'com.google.gms.google-services'
please help me what is problem I can't find out
i removed Androidx from my whole project but isue still parsist then
i found solution and replace
implementation 'androidx.core:core-ktx:1.0.0-alpha1'
to
implementation 'androidx.core:core-ktx:0.3'
and my problem is solved.
anyway thanks all second-time I'm going to use androidx (Android + Kotlin)
I'm waiting for jetpack stable version.
Actually this is a bug in Canary 14. You should wait for Canary 15 ;-)
Check out this session.
have you tried downloading android studio 3.2 canary 14? there is a new option to convert your files to androidX and will give you a preview of what it's going to do. Back up your files or at least use git to make sure it's safe.
thanks for the edit paul

Categories

Resources