Can't find android.support.design.widget.Snackbar in support design library
Asked Answered
Z

11

53

I develop own library module where I use Snackbar.

Here is my Gradle file:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'me.zhanghai.android.materialprogressbar:library:1.1.4'
    compile 'com.android.support:design:23.1.1'
}

As you can see, I have added import com.android.support:design:23.1.1, but as result I get error:

error: package android.support.design.R does not exist

How can I solve this problem?

Zellner answered 14/12, 2015 at 9:26 Comment(4)
Indeed the import package you've entered in your block quote is incorrect. This is the correct path import android.support.design.widget.SnackbarAspirator
change your build tool version to 23.1.1Glove
add, compile 'com.android.support:design:23.0.0'Juli
if you are migrating to Androidx then this might help https://mcmap.net/q/337151/-can-39-t-find-android-support-design-widget-snackbar-in-support-design-libraryPhonogram
M
94

You must add the design dependency in your gradle file (module app) according to


AndroidX build artifact

implementation "com.google.android.material:material:1.1.0-alpha06"


Old build artifact

implementation "com.android.support:design:28.0.0"


If you are using Support libraries, you can visit Support Library Packages  |  Android Developers, for the latest Design Support Library version. If you're new to AndroidX and want to use it, you can find more information about migrating to the new dependencies here.

Source: http://android-developers.blogspot.co.il/2015/05/android-design-support-library.html
(Scroll all the way down)

Melodiemelodion answered 9/4, 2016 at 10:44 Comment(4)
I've added compile 'com.android.support:design:23.1.1' But it does not help. Is there any difference between the changed versions ?Arv
Nothing significant code-wise, but I had many problems changing versions after a project starts, so I can only assume there are some other settings that need to be changed. If you have to change the version, try starting a new project and importing all the code and assets.Melodiemelodion
if you use android x dependency so implementation "com.google.android.material:material:1.0.0-rc01"Maddalena
if you are migrating to Androidx then this might help https://mcmap.net/q/337151/-can-39-t-find-android-support-design-widget-snackbar-in-support-design-libraryPhonogram
P
21

I solved the problem now :)

  1. Open [File] -> [Project Structure...]

  2. Select [app] in the left pad

  3. Select [Dependencies] in the right tabs

  4. Click [+] button on the right side

  5. Select [1 Library dependency]

  6. Choose [com.android.support:design ~~]

  7. Click [OK] button and so on

Result: library added in [Project's External Libraries]

------ edit -----------------------------------

You can also add this External library in build.gradle(Module:app)

press Alt+Enter in build.gradle(Module:app)

-> add library dependency

-> choose what you need

and press "Sync Now" positioned up right corner

Peaked answered 29/12, 2016 at 0:28 Comment(1)
if you are migrating to Androidx then this might help https://mcmap.net/q/337151/-can-39-t-find-android-support-design-widget-snackbar-in-support-design-libraryPhonogram
R
11

To get the the Snackbar into our Android proyect just add the reference of support:design library inside the build.gradle file :

dependencies {
    ...
    ...
    compile 'com.android.support:design:25.0.1'
}

Be sure to sync your project with the gradle files sync gradle icon, this will fix your problem.


Your error message is:

error: package android.support.design.R does not exist

be sure to have the correct import:

import android.support.design.widget.Snackbar;
Richly answered 19/4, 2017 at 17:59 Comment(0)
P
10

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"

Phonogram answered 30/11, 2019 at 11:11 Comment(0)
I
4
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'

set it in gradle.(module app) its working for me in android studio and device with orio.

Incoordinate answered 7/3, 2019 at 11:1 Comment(0)
V
4

After upgrading to androidx it will show error.You have to import this library

import com.google.android.material.snackbar.Snackbar;
 Snackbar snackbar = Snackbar.make(view, R.string.Mapview, Snackbar.LENGTH_INDEFINITE);
            View snackbarView = snackbar.getView();
            TextView textView = (TextView) snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
            textView.setMaxLines(5);
            snackbar.show();

Hope it will solve your problem.

Varela answered 11/6, 2020 at 9:52 Comment(1)
yes for that you have to add implementation "com.google.android.material:material:1.12.0" in your build.gradleBackfill
T
3

Try this

dependencies {
 compile fileTree(include: ['*.jar'], dir: 'libs')
 testCompile 'junit:junit:4.12'
 compile 'com.android.support:appcompat-v7:22.2.0'
 compile 'me.zhanghai.android.materialprogressbar:library:1.1.4'
 compile 'com.android.support:design:22.2.1'
 }
Toritorie answered 14/12, 2015 at 16:2 Comment(0)
W
3

Dependencies may change with upgrading of android sdk versions, i am creating application in sdkversion 27. I have added the following dependency for snackbar.
implementation 'com.android.support:design:27.1.1'

Winsor answered 30/4, 2018 at 10:26 Comment(0)
E
2

Just type fully qualified class name android.support.design.widget.SnackBar instead of just SnackBar at every occurrence . It solves the issue for me.

Edrei answered 6/1, 2017 at 20:35 Comment(1)
Solves my problem too.Arv
S
0

Remove Support v4 from your project and then add support design library.

Surplice answered 14/12, 2015 at 9:29 Comment(0)
D
0

Use implementation "com.android.support:design:23.0.0"

or Change the Sdk to 28 and use implementation "com.android.support:design:28.0.0"

Darra answered 6/10, 2019 at 21:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.