27

Google is recommending users to migrate from kotlin-android-extensions to kotlin-parcelize.

However, Gradle sync fails with the following error:

Plugin [id: 'kotlin-parcelize'] was not found in any of the following sources:

- Gradle Core Plugins (not a core plugin, please see https://docs.gradle.org/6.1.1/userguide/standard_plugins.html for available core plugins)
- Plugin Repositories (plugin dependency must include a version number for this source)

Where is the plugin located?

Some Noob Student
  • 14,186
  • 13
  • 65
  • 103

9 Answers9

36

kotlin-parcelize ships with Kotlin Plugin 1.4.20
(Release Announcement: Deprecation of Kotlin Android Extensions)

You need to upgrade your Kotlin versions and run Gradle sync again.

dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20"
}
Brown Smith
  • 754
  • 6
  • 6
29

1, update your AndroidStudio kotlin version
From menu, select Tools -> Kotlin -> Configure Kotlin Plugin Updates -> choose a kotlin version -> install -> and restart AS

2, update your dependencies classpath with the new kotlin version then sync project (like Brown Smith answer)

3
builld.gradle (:app)

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

MyObject.kt

import kotlinx.parcelize.Parcelize

@Parcelize
class MyObject(val name: String, val age: Int) : Parcelable {

}
Linh
  • 57,942
  • 23
  • 262
  • 279
  • Any idea why the following import still works even after removing the extensions plugin ? import kotlinx.android.parcel.Parcelize – Karan Sharma Aug 17 '21 at 06:42
  • not sure but maybe some other third party library that your application is using may include it @KaranSharma – Linh Aug 17 '21 at 08:21
8

This is the latest september 2021 implementation :

If you're using 'org.jetbrains.kotlin.android' version '1.5.20' or above , and you fail to find the parcelize tag , you can add it using the plugins DSL in the settings.gradle :

plugins {  
 id "org.jetbrains.kotlin.plugin.parcelize" version "1.6.0-M1" 
}

and then call it in your app build.gradle like this :

plugins { 
id 'org.jetbrains.kotlin.plugin.parcelize'
}
android gururu
  • 151
  • 1
  • 7
4

In your module level build.gradle file add,

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

In your project level build.gradle file add,

buildscript {
    ...
    repositories {
        google()
        jcenter()
    }
dependencies {
    ...
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32"
    
    }
}

Here '1.4.32' is the Kotlin package version. You will now be able to find the Parcelize package. Also while importing make sure to import:

import kotlinx.parcelize.Parcelize

package.

Boken
  • 4,825
  • 10
  • 32
  • 42
Anubhav
  • 1,984
  • 22
  • 17
  • 1
    Also remove plugin `kotlin-android-extensions` if was added, because they are incompatible together. But if you use synthetic, it wouldn't be possible. – CoolMind Oct 12 '21 at 20:31
4

Try this

in bulid.gradle (Project:*appname*) add:

buildscript {
    
    dependencies {
        ...
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
    }
}

and in bulid.gradle (Module:*appname*) add:

plugins {
    ...
    id 'org.jetbrains.kotlin.plugin.parcelize'
} 

If it didn't work for you check this link (if there's a new update): https://plugins.gradle.org/plugin/org.jetbrains.kotlin.plugin.parcelize

MoonX App
  • 97
  • 5
2

1. Make sure Gradle should be on Online mode

enter image description here

2. apply plugin: 'kotlin-parcelize'

3. need to upgrade your Kotlin versions 1.4.20 or above and run Gradle sync again.

dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
}
vijay saini
  • 361
  • 3
  • 6
1

in newest android studio in Nov 2021:

in setting.gradle add this line:

id("org.jetbrains.kotlin.plugin.parcelize") version "1.6.0-M1"

and in build.gradle of module:

 id("org.jetbrains.kotlin.plugin.parcelize")
Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44
1

Add this to your app level build.gradle file

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
kunal khedkar
  • 877
  • 8
  • 6
0

what worked for me is

  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
plugins {
   ...
    id 'kotlin-parcelize'
}
Sam
  • 241
  • 3
  • 7