How to Enable Kotlin Android Extensions by Default in Android Studio 4.1

家住魔仙堡 提交于 2021-01-18 05:28:27

问题


Why kotlin-android-extensions not enabled by default in this latest version of Android Studio? In fact, as long as i know, i have to manually add the plugin in gradle files. Any workaround so that i can add the plugin and enable it automatically everytime i create new project? Thanks before.

ICYMI, this is the code that needs to be added to enable kotlin-android

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

回答1:


In Kotlin 1.4.20-M2 JetBrains deprecated Kotlin Android Extensions compiler plugin.

kotlinx.android.synthetic is no longer a recommended practice. Removing in favour of explicit findViewById

Very sad news :(, i hate viewBinding




回答2:


In this commit you can see the message:

Replaced kotlinx synthetic with findViewById

kotlinx.android.synthetic is no longer a recommended practice. Removing in favour of explicit findViewById.

It says that it is no longer recommended, but that doesn't mean that you should not use it. They are providing guidelines, but you can choose what to use and what not.

Other alternatives:

  1. findViewById
  2. View Binding



回答3:


Android studio 4.1 do not support to import kotlin extension



来源:https://stackoverflow.com/questions/64431882/how-to-enable-kotlin-android-extensions-by-default-in-android-studio-4-1

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