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.
Related
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
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.
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.
I have gone through all stackoverflow examples but couldn't find a solution for my problem. I tried to downgrade mz sdk vesrion and android:support but it didn't work.
I am having the following code in build.gradle. However, whenever I try to build my gradle it shows an error: Failed to resolve: com.android.support... Anyway I am able to successfully install apk to my devices and it runs perfectly. I just don't want that his dependency will cause some error in the future.
Thanks!
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.feecollector.android.feecollector"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.navigation_menu.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:27.0.1-alpha1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'de.hdodenhof:circleimageview:1.3.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.navigation_menu:runner:1.0.2'
androidTestImplementation 'com.android.support.navigation_menu.espresso:espresso-core:3.0.2'
implementation 'com.facebook.android:facebook-android-sdk:4.36.0'
}
You are using different versions of com.android.support.
this is your code:
implementation 'com.android.support:appcompat-v7:27.0.1-alpha1'
implementation 'com.android.support:design:27.1.1'
it should be like this:
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
You have issue with gradle local setting. You can try to Invalidate and Restart cache. Click File -> Invalidate caches.
Sometimes you might even other issues with updating to new Gradle level. For this case, remove .idea and .gradle folders from Project Room and Import it again from Idea start screen.
Error:Failed to notify dependency resolution listener.
The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.2,15.0.2], [15.0.4,15.0.4]], but resolves to 15.0.4. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.intraday.geeks"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
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:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:design:26.1.0'
implementation 'com.google.firebase:firebase-core:15.0.4'
implementation 'com.google.android.gms:play-services-location:15.0.4'
implementation 'com.google.firebase:firebase-ads:15.0.1'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.0'
implementation 'com.firebaseui:firebase-ui:0.6.2'
}
apply plugin: 'com.google.gms.google-services'
Do you have the classpath 'com.google.gms:google-services:4.0.1'?
It is 4.0.1! I updated it from 4.0.0 to 4.0.1 and it is ok!
If it still doesn't work, you can do this, manually add and not use the plugin
There are several problems in your gradle, in general, the issue here is there is an incompatibility. With the latest Google Service version, Firebase an other Google libraries can be used in diferent version with no problem.
Upgrade your gradle: In the Project gradle, upgrade the gradle version
classpath 'com.android.tools.build:gradle:3.1.3'
You will have to updgrade gradle-wrapper.properties file as well
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Add in the project gradle the latest Google Services Version:
classpath 'com.google.gms:google-services:4.0.1'
Compile is no longer supported, so change it to implementation
implementation 'com.android.support:design:26.1.0'
Firebase-ui is no longer meant to be added all at once, remove it:
implementation 'com.firebaseui:firebase-ui:0.6.2' (delete that line)
Follow Firebase-ui docs to add the dependency you actually need