The 'kotlin-android-extensions' Gradle plugin is deprecated

做~自己de王妃 提交于 2021-02-04 05:38:32

问题


with the Gradle version 6.2 and Android studio version 4.0.1, I have the deprecation message for the Kotlin-android-extention. any body has any idea how to fix it.


回答1:


It's deprecated Base on the google document

Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported.

for those who's wonder what the synthetic is. I should say a simple way to access to UI view id with kotlin which was possible by adding 'kotlin-android-extensions' in Gradle.

  • If your app uses Parcelable you can use 'kotlin-parcelize' instead of 'kotlin-android-extensions'.
  • If your app uses Kotlin synthetics for view binding, use this guide to migrate to Jetpack ViewBinding or Data Binding.



回答2:


It's deprecated now

  • Remove 'Kotlin-android-extention' from the plugin. (Used for kotlin's synthetic way to access UI elements)

  • Add below to use view binding way to access UI element

    android {
       ...
       buildFeatures {
           viewBinding true
       }
    }
    
  • If your app contains Parcelable, please add 'kotlin-parcelize' in plugin to use a simple way to create parcelable by just adding @Parcelize annotation to class

You can see the Google guideline regarding this update.




回答3:


The above answers are correct, but when you remove 'kotlin-android-extensions' from your project, accessing view properties using kotlin's synthetic way won't be possible, so you need to migrate to use view binding, follow Google's this guide for migrating to view binding: link




回答4:


As already stated, Kotlin Synthetics is deprecated and should be replaced by View Binding. In my case I wanted to introduce View Binding and gradually migrate from Kotlin Synthetics. It's possible to have both in one project, you just need to remember not to update Kotlin version - I had a build error with 4.1.21, so needed to downgrade to 1.4.10.

Also remember to delete Kotlin Synthetics imports from a class (usually activity/fragment), which has been migrated to using View Binding.



来源:https://stackoverflow.com/questions/65179275/the-kotlin-android-extensions-gradle-plugin-is-deprecated

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