26

My project's migration to View Binding is underway but in the meantime this warning is distracting when looking at build logs

Warning: The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.

How can I disable it?

kassim
  • 3,880
  • 3
  • 26
  • 27

5 Answers5

28

I also recently faced this problem and found out.

In Kotlin 1.4.20-M2, JetBrains deprecated the Kotlin Android Extensions compiler plugin in favor of View Binding, and Also, Google is promoting modularisation, but synthetic properties don’t work cross-module.

So to fix this warning. Remove apply plugin: 'kotlin-android-extensions' in your build.gradle file

Note: If you're using Parcelize.

Don’t forget that the Parcelize feature in Kotlin is part of the kotlin-android-extensions compiler plugin, so removing the plugin will end up making all your Parcelable classes not compiling if they depend on the Parcelize annotation.

JetBrains extracted the Parcelize from Kotlin Android Extensions to a new plugin, kotlin-parcelize

First, you will need to add kotlin-parcelize plugin to your project build.gradle file.

Plugins {
   ...
   id 'kotlin-parcelize'
}

Then change your old import statement from

import kotlinx.android.parcel.Parcelize

to

import kotlinx.parcelize.Parcelize

For more info, I recommend you to read this Blog Migrating the deprecated Kotlin Android Extensions compiler plugin

Muhammad Farhan
  • 1,113
  • 10
  • 22
  • 1
    As I understand the plugin is `id 'kotlin-parcelize'` not `id 'Kotlin-parcelize'` i.e **k** in **k**otlin-parcelize is lowercase. Please edit the answer so that there is no confusion, thank you. PS: Single character edits are not allowed by a different user. – Saharsh Nov 05 '21 at 09:42
  • 1
    And if you removed apply plugin: 'kotlin-android-extensions' dont forget to remove androidExtensions {experimental = true} as well ;) – MehrAmoon Dec 07 '21 at 15:05
  • both worked . idk how . despite of your correct answer, both worked :D – Exutic May 16 '22 at 21:18
15

Just you need to remove this line from your Gradle:

apply plugin: 'kotlin-android-extensions'
2

I hope it helps for future readers.

build.gradle (:app) :

android
{
...
    buildFeatures 
    {
        viewBinding = true
    }
}

Add it to the Kotlin-plot. because it does the functionality that 'kotlin-android-extensions' provides.

plugins 
{
    ...
    id 'kotlin-parcelize'
}

You have to set minifyEnabled to True

buildTypes 
   {
        release 
        {
            minifyEnabled true
            ...
        }
    }

MainActivity.kt

import com.hakanbayazithabes.firstproject.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() 
{
    private  lateinit var binding: ActivityMainBinding _//add here_

    override fun onCreate(savedInstanceState: Bundle?) 
     {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater) _//add here_
        val view = binding.root _//add here_
        setContentView(view) _//add here_
        //setContentView(R.layout.activity_main)
     }

    fun Change(view : View){
        binding.textView.text = "Hello Android" _//worked_
     }
}
1

Follow the steps:

  1. kotlin-android-extensions is deprecated so replace it from kotlin-parcelize
  2. If there is @Parcelize annotation used for model classes so you have to replace its import from kotlinx.android.parcel.Parcelize to import kotlinx.parcelize.Parcelize
Sibtain Raza
  • 205
  • 2
  • 4
-4

The report is a warning that you are using a deprecated plugin, I don't understand why you would want to disable it since sooner or later I expect the compile will fail and you may not remember why.

The article says: "If your app does not use Parcelize features, remove the line that enables Kotlin Android Extensions: (aka, just remove the line apply plugin: 'kotlin-android-extensions'). It may turn out you don't need the plugin, hard to say since you didn't indicate if you are using any features supplied by the deprecated plugin.

If you are annotating any classes with 'Parcelable' then there is a bit or work you will need to do, as indicated in the article.

Edit: also gone is view synthetics (the feature that allowed you to not use all those 'findViewById'. that's (IMO) is the larger loss and I have not yet ported my apps over so I cannot comment on the amount of work it will take to move.

For the immediate future, I've chosen to wait and implement the new code later but you will need to make your own decision as to when it's appropriate to migrate away from the deprecated plugin.

Kenneth Argo
  • 1,697
  • 12
  • 19
  • You can use `kotlin-parcelize` to replace the `@Parcelize` behavior of the old KAE. It is as simple as replacing `import kotlinx.android.parcel.Parcelize` with `import kotlinx.parcelize.Parcelize` – EpicPandaForce May 26 '21 at 20:50