Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 622
Sergey Android Avatar asked Dec 14 '15 09:12

Sergey Android


3 Answers

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)

like image 132
Max Izrin Avatar answered Oct 16 '22 16:10

Max Izrin


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

like image 37
yane Avatar answered Oct 16 '22 14:10

yane


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;
like image 11
Jorgesys Avatar answered Oct 16 '22 15:10

Jorgesys