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

时光毁灭记忆、已成空白 提交于 2020-12-30 04:55:35

问题


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


回答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.




回答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'
}



回答3:


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"
}



回答4:


For me it was just adding the apply plugin: 'kotlin-android-extensions' to app's build.gradle, press sync gradle files and i was able to get synthetics




回答5:


Simple friend, you forgot the asterisk.

    import kotlinx.android.synthetic.main.activity_main.*

It just happened to me.




回答6:


this fixed it for me :

  1. Put this into your app.iml

<facet type="kotlin-language" name="Kotlin"> <configuration version="3" platform="JVM 1.8" allPlatforms="JVM [1.8]" useProjectSettings="false"> <compilerSettings /> <compilerArguments> <option name="jvmTarget" value="1.8" /> <option name="pluginOptions"> <array> <option value="plugin:org.jetbrains.kotlin.android:enabled=true" /> <option value="plugin:org.jetbrains.kotlin.android:defaultCacheImplementation=hashMap" /> </array> </option> </compilerArguments> </configuration> </facet>

  1. Do gradle sync



回答7:


id 'kotlin-android-extensions'
id 'kotlin-android'

remove plugins and added them two of them. id 'kotlin-android-extensions' id 'kotlin-android'

should be added. restart the project.

So the problem as I have found is in gradle plugins, then you need to restart, rebuild your project.




回答8:


Synthetics are now deprecated from Google. Try to avoid using them as it might lead to null pointer exceptions and unexpected behaviour on your app.

Read more on:

Migrate from Kotlin synthetics to Jetpack view binding from official developers site.



来源:https://stackoverflow.com/questions/52271521/import-kotlinx-android-synthetic-main-activity-main-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!