com.google.android.material.R Cannot resolve symbol 'R' for BottomNavigationView
Asked Answered
G

4

6

I use BottomNavigationView in my App, but I have a problem: in BottomNavigationView.java there is import com.google.android.material.R and R is red and write "Cannot resolve symbol 'R'". The topics I saw couldn't help me.

What would you recommend for me?

The dependencies:

    apply plugin: 'com.android.application'
android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example.yourspeakingclub"
        minSdkVersion 24
        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 JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    sourceSets {
        main {
            java.srcDirs = ['src/main/java', 'src/main/java/Models', 'src/main/java/com/salendor/yourspeakingclub/models']
        }
    }
    buildToolsVersion = '28.0.3'
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.android.support:support-compat'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    testImplementation 'junit:junit:4.13-beta-3'
    androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
    implementation 'com.google.android.material:material:1.1.0-beta01'
}

The layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/navigation_container_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?android:attr/actionBarSize">

<com.google.android.material.bottomnavigation.BottomNavigationView

    android:id="@+id/navigation_element"
    android:layout_width="wrap_content"
    android:layout_height="56dp"
    android:layout_gravity="start"
    android:background="?android:attr/windowBackground"
    app:itemTextColor="#000000"
    app:labelVisibilityMode="unlabeled"
    app:itemIconTint="@color/colorBlack"
    app:menu="@menu/bottom_menu" />

</FrameLayout>

The class definition where is the problem with 'R' is available here: https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/bottomnavigation/BottomNavigationView.java

Thanks

Glabrescent answered 15/10, 2019 at 17:40 Comment(0)
A
3

The error should be resolved by doing Alt+Enter & adding the right import. But I'm guessing this issue came out of nowhere after you had already built & run the project at least once (as it once happened with me). This could be because you're unable to reference the elements of the XML layout. In this case, try:

Build -> Clean project

. This resolved my issue. Hopefully, it'll help you too :)

Artiste answered 21/8, 2021 at 4:43 Comment(0)
X
1

I experienced this problem when I updated Gradle to the latest version. When I returned to version 3.1.3 the error simply disappeared

change this in your build.graddle (project)

        classpath 'com.android.tools.build:gradle:3.1.3'
Xenophon answered 19/4, 2020 at 15:3 Comment(1)
This is solution is working just fine but its a short time solution when you close and open android studio again the problem still persistsChristinachristine
B
0

I had the same problem. Simply updated this tool in build.graddle (project) file

classpath 'com.android.tools.build:gradle:4.1.0'

and it worked !!

Baker answered 17/10, 2020 at 14:30 Comment(0)
S
0

If you can compile the project and it´s just a "fake" unresolved reference, then you should just clean your project.

Build -> Clean project

After that, everything should work.

Surgical answered 30/10 at 0:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.