tarun14110
tarun14110

Reputation: 990

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'

Upvotes: 0

Views: 5338

Answers (4)

AskNilesh
AskNilesh

Reputation: 69699

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"

Upvotes: 8

David Luz
David Luz

Reputation: 1

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.

Upvotes: 0

Sagar
Sagar

Reputation: 24917

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.

Upvotes: 2

Mayur Patel
Mayur Patel

Reputation: 2326

designYou need to add in dependencies in your build.gradle file.

 implementation 'com.android.support:design:27.1.1'

And Sync your project.

Upvotes: 1

Related Questions