Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plugin 'kotlin-parcelize' not found

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?

like image 447
Some Noob Student Avatar asked Nov 24 '20 06:11

Some Noob Student


People also ask

How do I add Parcelize?

Just add the @Parcelize annotation to a class implementing the Parcelable interface and the Parcelable implementation will be generated automatically. This is the same example as in the previous article, in just 2 lines of code. The class can be a data class but it's optional.


Video Answer


3 Answers

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"
}
like image 188
Brown Smith Avatar answered Oct 11 '22 01:10

Brown Smith


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 {

}
like image 42
Linh Avatar answered Oct 11 '22 01:10

Linh


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'
}
like image 38
android gururu Avatar answered Oct 11 '22 01:10

android gururu