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"
}
Author by
Admin
Updated on July 08, 2022Comments
-
Admin almost 2 years
Import kotlinx greyed out
I think i try nearly everything. Reinstall Android Studio, Invalide Cache, new Project same Problem.
i just can't find the Solution
-
Admin over 5 yearsi add it to my file but its greyed out and its says "Unused import directive"
-
Khemraj Sharma over 5 yearsDid 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 over 5 yearsthat verry weird the import line Disappears when i try to add a id to my class
-
Admin over 5 yearsThank you so much, i dont know how but now its working
-
TootsieRockNRoll about 5 yearsDeleting .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 over 3 yearsThe answer is worked for me (apply plugin: 'kotlin-android-extensions') & after Invalidate Caches / Restart
-
ralphgabb about 3 yearsThis worked. I think there is a bug on the new Android Studio 4.1 version that excludes extension at project creation.
-
Sabir Syed over 2 yearsIt works for me. Thanks
-
Ahmed Nezhi over 2 yearsworked for me, thanks
-
Marco Giovanni over 2 yearsMy 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 over 2 yearsThis was my answer. Thanks.