'Cannot resolve symbol' (design + v7 + annotation) - android

A friend of mine sent me some activity from his app. I created a new activity for each one and copy-paste the code in the new empty activity. Now I got some problem with the imports:
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.RecyclerView;
import android.support.annotation.Nullable;
And here there is my Gradle - app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.progand"
minSdkVersion 26
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 fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
}
I tried adding all the depedences that i found online and nothing solved the problem, it still gives me the error "cannot resolve symbol 'design/v7/annotation' " and I can't run my app to test the activities.
I really dunno what I'm doing wrong, sorry if it seems naive but it's my first time trying android studio 3.4.2, SDK Version 29.0.2.

Do not mix com.android.support and androidx artifact. You should be using all the dependencies of androidx only.
Replace
implementation 'com.android.support:design:28.0.0' with implementation 'com.google.android.material:material:1.1.0-alpha08'.
Remove implementation 'com.android.support:recyclerview-v7:28.0.0' since you already have androidx dependency of RecyclerView.
Now See Artifact mapping.. Use same latest versions for all androidx libraries.
Check out Class mapping.
android.support.design.widget.TextInputEditText =====> com.google.android.material.textfield.TextInputEditText
android.support.design.widget.TextInputLayout ======> com.google.android.material.textfield.TextInputLayout

Related

Cannot Resolve Symbol Content In Android 3.6.1

I have searched many post of related this question here but not found any solution of my issue. That's why I am here.
I have recently updated to Android Studio 3.6.1 and raised the issue of " Cannot Resolve Symbol Content"
my import library is as below:
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
above import library not working in Android 3.6.1. how to solve this issue?. please suggest
Note:- I have tried Several answer related to this post but it is remain unsolved.
I have deleted Build/ .Gradle and .idea and rebuild the project but not works. I have also tried another solution of this question as below.
close the current project
remove all the project by X sign
Closed the Andoid studio
Again restart project by open exist project
but all the efforts are failed. Provide me right solution.
my build.gradle file is as under.
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.maheshwaghela.mahesh.rukhivivah"
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'
}
}
compileOptions {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
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 'de.hdodenhof:circleimageview:3.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.android.volley:volley:1.1.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
}
Since you've migrated to androidx and those imports are for the old support libraries you should use newer ones instead. Remove those with these:
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
Try if these solve your issue.
For a more complete list of from your current mappings of the old support library packages to the new androidx packages, you can refer the official docs.

Can't import android.support.v7 and annotation libary with gradle

Im trying to go through this tutorial Android Implementing Preferences Settings Screen
He imports android.support.v7... and android.suppor.annotation libary...
I did the most suggested answer and implemented these packages to my build.gradle and resynced it.
Android studio can't resolve v7 and annotations.
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
gradle.build:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "info.androidhive.preferences"
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.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.android.support:appcompat-v7:+'
}
I expected, that after resyncing the libarys would be available and not the error message
cant resolve symbol v7 for instance.
Thanks for help.
You are using androidx: implementation 'androidx.appcompat:appcompat:1.0.2'.
In your code you have to import the correct class:
import androidx.appcompat.widget.Toolbar;
Also remove in your build.gradle
//implementation 'com.android.support:appcompat-v7:+'
For the annotations use:
androidx.annotation:annotation:1.1.0

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.

Android Studio "unused import" message when putting SDK inside build.gradle

I'm trying to insert an SDK called Mesibo for communication, and in my project it instantly greys out when I try to import: import com.mesibo.api.mesibo; with the message cannot resolve symbol 'mesibo' and unused import around it
This is the build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.richard.myapplication"
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 'com.mesibo.api:mesibo:1.0.5'
implementation 'com.mesibo.api:calls:1.0.3'
implementation 'com.mesibo.api:ui:1.0.4'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
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'
}
import com.mesibo.api.mesibo;
I'm following their documentation, and the import stops gradle from syncing with the project for some reason. I'm very new to Android Studio and this is my first time attempting to place an SDK + API in.
This goes in your Java/Kotlin code, not in Gradle
import com.mesibo.api.mesibo;
So remove it from there, and then compile the code, then add it to the other source files you need this class.
And I think that their documentation is very poor... should be
import com.mesibo.api.Mesibo;
https://github.com/mesibo/samples/tree/master/android/MesiboSample/app/src/main/java/com/mesibo/firstsample

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.

Categories

Resources