import kotlinx.android.synthetic.main.activity_main is not working
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
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'
}
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.
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.*
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"
}
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