import kotlinx.android.synthetic.main.activity_main is not working

68,839

Solution 1

Can you try

  • File | Invalidate Caches / Restart
  • Deleting .idea folder
  • Clean
  • Re-import the project

OR just remove apply plugin: 'kotlin-android-extensions' , sync gradle plugin and then I added it again.

Solution 2

Check "build.gradle(:app)" file,

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

if kotlin extension is missing, add kotlin-android-extensions as shown below and click on "Sync now"

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

Solution 3

Just add below line in your build.gradle(Module:YourProjectName.app) inside the plugins section on top:

plugins{
       id 'com.android.application'
       id 'kotlin-android'
       id 'kotlin-android-extensions'
}

Mostly first two lines are already there just need to add 3rd one and sync project

Solution 4

Here is a step by step answer:

  • From right side of the Android studio click on Gradle
  • Right click on the app and click Open Gradle Config
  • New source opening in plugins part and then add this:

id 'kotlin-android-extensions'

  • Tap sync

Result: now you can import kotlinx.android.synthetic.main.activity_main.*

Solution 5

module gradle

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

dependencies {
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

project gradle

buildscript{
ext.kotlin_version = '1.3.11'
}
 dependencies {
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Share:
68,839
Admin
Author by

Admin

Updated on July 08, 2022

Comments

  • Admin
    Admin almost 2 years

    Import kotlinx greyed out

    enter image description here

    I think i try nearly everything. Reinstall Android Studio, Invalide Cache, new Project same Problem.

    i just can't find the Solution

  • Admin
    Admin over 5 years
    i add it to my file but its greyed out and its says "Unused import directive"
  • Khemraj Sharma
    Khemraj Sharma over 5 years
    Did you try running your app? unused simply mean, it is not used yet, it will be used when you use some id in your class.
  • Admin
    Admin over 5 years
    that verry weird the import line Disappears when i try to add a id to my class
  • Admin
    Admin over 5 years
    Thank you so much, i dont know how but now its working
  • TootsieRockNRoll
    TootsieRockNRoll about 5 years
    Deleting .idea folder worked for me, I think it started happening because I switch branched and AS didn't know how to go from there
  • Bolt UIX
    Bolt UIX over 3 years
    The answer is worked for me (apply plugin: 'kotlin-android-extensions') & after Invalidate Caches / Restart
  • ralphgabb
    ralphgabb about 3 years
    This worked. I think there is a bug on the new Android Studio 4.1 version that excludes extension at project creation.
  • Sabir Syed
    Sabir Syed over 2 years
    It works for me. Thanks
  • Ahmed Nezhi
    Ahmed Nezhi over 2 years
    worked for me, thanks
  • Marco Giovanni
    Marco Giovanni over 2 years
    My project compiled, but an IDEA showed an error, I just removed the kotlin-android-extensions -> sync, and added it again and it worked again
  • anjanesh
    anjanesh over 2 years
    This was my answer. Thanks.