最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

unable to import id("kotlin-parcelize") and navigation safe args in new android studio version - Stack Overflo

programmeradmin4浏览0评论

I just updated my Android Studio to the last version and start creating new project and I am facing problems with the latest Android dependencies system

firstly I tried with id("kotlin-parcelize") then I changed it to alias(libs.plugins.kotlin.parcelize) and it's added correctly in libs.versions.toml file

but I still see an error in my model class

I also see this error AssertionError: Number of arguments should not be less than number of parameters, but: parameters=6, args=4 especially after added safe args dep

this all my dependencies in libs.versions.toml file


[versions]
agp = "8.9.0"
kotlin = "2.0.21"
coreKtx = "1.15.0"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
appcompat = "1.7.0"
viewModel = "2.8.7"
liveData = "2.8.7"
lifecycle = "2.8.7"
material = "1.12.0"
activity = "1.10.1"
constraintlayout = "2.2.1"
coroutines = "1.8.0"
hiltVersion = "2.56"
safeargs = "2.8.9"


[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
androidx-viewmodel = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "viewModel" }
androidx-livedata = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "liveData" }
androidx-lifecycle = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
coroutines = { group = ".jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" }
dagger-hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "hiltVersion" }
androidx-navigation-safeargs = { group = "androidx.navigation", name = "navigation-safe-args-gradle-plugin", version.ref = "safeargs"}
dagger-hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hiltVersion" }


[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = ".jetbrains.kotlin.android", version.ref = "kotlin" }
safeargs-plugin = { id = "androidx.navigation.safeargs", version.ref = "safeargs" }
android-library = { id = "com.android.library", version.ref = "agp" }
dagger-hilt-plugin = { id = "com.google.dagger.hilt.android", version.ref = "hiltVersion" }
ksp = { id = "com.google.devtools.ksp", version = '2.0.21-1.0.27' }
kotlin-parcelize = { id = ".jetbrains.kotlin.plugin.parcelize" } # Added this line

build.gradle.kts (app)

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.android)
    alias(libs.plugins.dagger.hilt.plugin)
    alias(libs.plugins.ksp)
    alias(libs.plugins.kotlin.parcelize)
    alias(libs.plugins.safeargs.plugin)


}

android {
    namespace = "com.example.mmlaudioplayer"
    compileSdk = 35

    defaultConfig {
        applicationId = "com.example.mmlaudioplayer"
        minSdk = 23
        targetSdk = 35
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures {
        viewBinding = true
    }


    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = "11"
    }
}

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.appcompat)
    implementation(libs.material)
    implementation(libs.androidx.activity)
    implementation(libs.androidx.constraintlayout)
    implementation(libs.coroutines)
    implementation(libs.dagger.hilt)
    ksp(libs.dagger.hiltpiler)
    implementation(libs.androidx.viewmodel)
    implementation(libs.androidx.livedata)
    implementation(libs.androidx.lifecycle)

    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
}

IDE version

Android Studio Meerkat | 2024.3.1
Build #AI-243.22562.218.2431.13114758, built on February 25, 2025
Runtime version: 21.0.5+-12932927-b750.29 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.windows.WToolkit
Windows 11.0
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 28
Registry:
  ide.instant.shutdown=false
  ide.experimental.ui=true
  i18n.locale=
Non-Bundled Plugins:
  wu.seal.tool.jsontokotlin (3.7.6)
  com.gionchat.json.bean (1.0.5)
  com.robohorse.robopojogenerator (2.6.3)
  com.jetbrains.edu (2025.2-2024.3-1399)
  com.thoughtworks.gauge (243.22562.238)

I just updated my Android Studio to the last version and start creating new project and I am facing problems with the latest Android dependencies system

firstly I tried with id("kotlin-parcelize") then I changed it to alias(libs.plugins.kotlin.parcelize) and it's added correctly in libs.versions.toml file

but I still see an error in my model class

I also see this error AssertionError: Number of arguments should not be less than number of parameters, but: parameters=6, args=4 especially after added safe args dep

this all my dependencies in libs.versions.toml file


[versions]
agp = "8.9.0"
kotlin = "2.0.21"
coreKtx = "1.15.0"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
appcompat = "1.7.0"
viewModel = "2.8.7"
liveData = "2.8.7"
lifecycle = "2.8.7"
material = "1.12.0"
activity = "1.10.1"
constraintlayout = "2.2.1"
coroutines = "1.8.0"
hiltVersion = "2.56"
safeargs = "2.8.9"


[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
androidx-viewmodel = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "viewModel" }
androidx-livedata = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "liveData" }
androidx-lifecycle = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
coroutines = { group = ".jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" }
dagger-hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "hiltVersion" }
androidx-navigation-safeargs = { group = "androidx.navigation", name = "navigation-safe-args-gradle-plugin", version.ref = "safeargs"}
dagger-hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hiltVersion" }


[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = ".jetbrains.kotlin.android", version.ref = "kotlin" }
safeargs-plugin = { id = "androidx.navigation.safeargs", version.ref = "safeargs" }
android-library = { id = "com.android.library", version.ref = "agp" }
dagger-hilt-plugin = { id = "com.google.dagger.hilt.android", version.ref = "hiltVersion" }
ksp = { id = "com.google.devtools.ksp", version = '2.0.21-1.0.27' }
kotlin-parcelize = { id = ".jetbrains.kotlin.plugin.parcelize" } # Added this line

build.gradle.kts (app)

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.android)
    alias(libs.plugins.dagger.hilt.plugin)
    alias(libs.plugins.ksp)
    alias(libs.plugins.kotlin.parcelize)
    alias(libs.plugins.safeargs.plugin)


}

android {
    namespace = "com.example.mmlaudioplayer"
    compileSdk = 35

    defaultConfig {
        applicationId = "com.example.mmlaudioplayer"
        minSdk = 23
        targetSdk = 35
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures {
        viewBinding = true
    }


    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = "11"
    }
}

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.appcompat)
    implementation(libs.material)
    implementation(libs.androidx.activity)
    implementation(libs.androidx.constraintlayout)
    implementation(libs.coroutines)
    implementation(libs.dagger.hilt)
    ksp(libs.dagger.hiltpiler)
    implementation(libs.androidx.viewmodel)
    implementation(libs.androidx.livedata)
    implementation(libs.androidx.lifecycle)

    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
}

IDE version

Android Studio Meerkat | 2024.3.1
Build #AI-243.22562.218.2431.13114758, built on February 25, 2025
Runtime version: 21.0.5+-12932927-b750.29 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.windows.WToolkit
Windows 11.0
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 28
Registry:
  ide.instant.shutdown=false
  ide.experimental.ui=true
  i18n.locale=
Non-Bundled Plugins:
  wu.seal.tool.jsontokotlin (3.7.6)
  com.gionchat.json.bean (1.0.5)
  com.robohorse.robopojogenerator (2.6.3)
  com.jetbrains.edu (2025.2-2024.3-1399)
  com.thoughtworks.gauge (243.22562.238)
Share Improve this question asked Mar 22 at 21:44 Dr MidoDr Mido 2,6736 gold badges39 silver badges80 bronze badges 2
  • "Internal error" sounds like something unexpected happened during code analysis. Have you tried restarting Android Studio? Did you do a Gradle clean? Did you Invalidate caches? Sometimes it is even enough to do Ctrl+A, Ctrl+X, Ctrl+V, simply emptying the current file annd reinserting everything. – tyg Commented Mar 22 at 22:34
  • I have already taken these steps, but I still see this error. The strange thing is that I created another new project and only added the Navigation library, and I got the same error, even though I ran the app in an emulator, and it worked. This is weird; maybe it's a bug – Dr Mido Commented Mar 22 at 22:39
Add a comment  | 

2 Answers 2

Reset to default 1

For build.gradle.kt (app),

plugins {
    alias(libs.plugins.navigation.safe.args)
    alias(libs.plugins.kotlin.parcelize)
}

For build.gradle.kt (project),

plugins {
    alias(libs.plugins.navigation.safe.args) apply false
    alias(libs.plugins.kotlin.parcelize) apply false
}

In libs.version.toml, declare plugin and version as follow

[versions]
kotlin = "2.1.10"
navigationSafeArgsGradlePlugin = "2.8.9"

[plugins]
navigation-safe-args = { id = "androidx.navigation.safeargs.kotlin", version.ref = "navigationSafeArgsGradlePlugin" }
kotlin-parcelize = { id = ".jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }

check this out. It works for me. https://www.youtube/watch?v=-r8m2qNJ3Sg

If you see carefully, the method to add kotlin-parcelize in Android Studio Meerkat is the same process than previous versions. Add the plug in in the file build.gradle.kts (Module).

id("kotlin-parcelize")

plus a new step. Add the plugin in build.gradle.kts(project) as follows

id(".jetbrains.kotlin.plugin.parcelize") version libs.versions.kotlin apply false

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论