Mani Bharathy
Mani Bharathy

Reputation: 117

Unresolved reference: android

enter image description here

As you can see from the image, Android studio is not able to resolve this import "com.android" in this line.

import com.android.volley.toolbox.Volley

I tried the following truobleshooting found from some other answers:

  1. Clean and rebuild
  2. File -> invalidate caches and restart
  3. Opening the project by build.gradle
  4. Deleting the .idea folder in the project
  5. Installing old sdk (Android 6.0) along with latest

But none seem to be helping. Help please.

build.gradle (module) file : https://textsaver.flap.tv/lists/326r

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "..."
        minSdkVersion 15
        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.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

}

Upvotes: 2

Views: 20025

Answers (4)

Sometimes for any reason, the following line appears among the imports

import android.R

This caused (at least in my case) the error Unresolved reference: android.

After removing this line, the error disappears.

Upvotes: 0

wonsuc
wonsuc

Reputation: 3634

It sounds stupid, but in my case, I had build.gradle and build.gradle.kts files at the same time in the :app module folder.

After deleting build.grale file it worked correctly.

Upvotes: 0

Md. Asaduzzaman
Md. Asaduzzaman

Reputation: 15433

As I thought you forgot to add dependency in your gradle file. Add dependency to module level build.gradle file

dependencies {
    ...
    implementation 'com.android.volley:volley:1.1.1'
}

Upvotes: 2

alhamwa
alhamwa

Reputation: 79

Try to delete the build folder then resynchronize. Sometimes even using ./gradlew clean command, the generated file not deleted correctly

Upvotes: 1

Related Questions