“SAVED_STATE_REGISTRY_OWNER_KEY” 出现错误的原因可能是什么?

huangapple go评论112阅读模式
英文:

What could be the reason for the error "SAVED_STATE_REGISTRY_OWNER_KEY"?

问题

Good afternoon, I am writing an application for working with the network on jetpack compose using a clean architecture, and I encountered an error

  1. java.lang.IllegalArgumentException: CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`

Gradle项目

  1. buildscript {
  2. ext {
  3. compose_ui_version = '1.1.1'
  4. }
  5. } // 顶级构建文件,您可以在其中添加所有子项目/模块的通用配置选项。
  6. plugins {
  7. id 'com.android.application' version '7.3.1' apply false
  8. id 'com.android.library' version '7.3.1' apply false
  9. id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
  10. id 'com.google.dagger.hilt.android' version '2.44' apply false
  11. }

Gradle模块

  1. plugins {
  2. id 'com.android.application'
  3. id 'org.jetbrains.kotlin.android'
  4. id 'kotlin-kapt'
  5. id 'dagger.hilt.android.plugin'
  6. }
  7. android {
  8. namespace 'com.example.kotlinretrofit'
  9. compileSdk 33
  10. defaultConfig {
  11. applicationId "com.example.kotlinretrofit"
  12. minSdk 24
  13. targetSdk 33
  14. versionCode 1
  15. versionName "1.0"
  16. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  17. vectorDrawables {
  18. useSupportLibrary true
  19. }
  20. }
  21. buildTypes {
  22. release {
  23. minifyEnabled false
  24. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  25. }
  26. }
  27. compileOptions {
  28. sourceCompatibility JavaVersion.VERSION_1_8
  29. targetCompatibility JavaVersion.VERSION_1_8
  30. }
  31. kotlinOptions {
  32. jvmTarget = '1.8'
  33. }
  34. buildFeatures {
  35. compose true
  36. }
  37. composeOptions {
  38. kotlinCompilerExtensionVersion '1.1.1'
  39. }
  40. packagingOptions {
  41. resources {
  42. excludes += '/META-INF/{AL2.0,LGPL2.1}'
  43. }
  44. }
  45. }
  46. dependencies {
  47. implementation 'androidx.core:core-ktx:1.7.0'
  48. implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
  49. implementation 'androidx.activity:activity-compose:1.3.1'
  50. implementation "androidx.compose.ui:ui:$compose_ui_version"
  51. implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
  52. implementation 'androidx.compose.material:material:1.1.1'
  53. testImplementation 'junit:junit:4.13.2'
  54. androidTestImplementation 'androidx.test.ext:junit:1.1.5'
  55. androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
  56. androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
  57. debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
  58. debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
  59. // Retrofit
  60. implementation 'com.squareup.retrofit2:retrofit:2.9.0'
  61. implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
  62. implementation "com.squareup.okhttp3:okhttp:4.9.3"
  63. implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
  64. implementation "androidx.compose.runtime:runtime-livedata:1.4.0-alpha04"
  65. // Coroutines
  66. implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
  67. implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
  68. // Coroutine Lifecycle Scopes
  69. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
  70. implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"
  71. // Hilt
  72. implementation "com.google.dagger:hilt-android:2.44"
  73. kapt "com.google.dagger:hilt-compiler:2.44"
  74. }

根据我理解,这个错误与依赖关系有关,但所有依赖关系都是从10天前的视频中获取的。我尝试省略gradle版本,但它没有起作用。

英文:

Good afternoon, I am writing an application for working with the network on jetpack compose using a clean architecture, and I encountered an error

  1. java.lang.IllegalArgumentException: CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`

Gradle project

  1. buildscript {
  2. ext {
  3. compose_ui_version = '1.1.1'
  4. }
  5. }// Top-level build file where you can add configuration options common to all sub-projects/modules.
  6. plugins {
  7. id 'com.android.application' version '7.3.1' apply false
  8. id 'com.android.library' version '7.3.1' apply false
  9. id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
  10. id 'com.google.dagger.hilt.android' version '2.44' apply false
  11. }

Gradle module

  1. plugins {
  2. id 'com.android.application'
  3. id 'org.jetbrains.kotlin.android'
  4. id 'kotlin-kapt'
  5. id 'dagger.hilt.android.plugin'
  6. }
  7. android {
  8. namespace 'com.example.kotlinretrofit'
  9. compileSdk 33
  10. defaultConfig {
  11. applicationId "com.example.kotlinretrofit"
  12. minSdk 24
  13. targetSdk 33
  14. versionCode 1
  15. versionName "1.0"
  16. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  17. vectorDrawables {
  18. useSupportLibrary true
  19. }
  20. }
  21. buildTypes {
  22. release {
  23. minifyEnabled false
  24. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  25. }
  26. }
  27. compileOptions {
  28. sourceCompatibility JavaVersion.VERSION_1_8
  29. targetCompatibility JavaVersion.VERSION_1_8
  30. }
  31. kotlinOptions {
  32. jvmTarget = '1.8'
  33. }
  34. buildFeatures {
  35. compose true
  36. }
  37. composeOptions {
  38. kotlinCompilerExtensionVersion '1.1.1'
  39. }
  40. packagingOptions {
  41. resources {
  42. excludes += '/META-INF/{AL2.0,LGPL2.1}'
  43. }
  44. }
  45. }
  46. dependencies {
  47. implementation 'androidx.core:core-ktx:1.7.0'
  48. implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
  49. implementation 'androidx.activity:activity-compose:1.3.1'
  50. implementation "androidx.compose.ui:ui:$compose_ui_version"
  51. implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
  52. implementation 'androidx.compose.material:material:1.1.1'
  53. testImplementation 'junit:junit:4.13.2'
  54. androidTestImplementation 'androidx.test.ext:junit:1.1.5'
  55. androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
  56. androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
  57. debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
  58. debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
  59. // Retrofit
  60. implementation 'com.squareup.retrofit2:retrofit:2.9.0'
  61. implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
  62. implementation "com.squareup.okhttp3:okhttp:4.9.3"
  63. implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
  64. implementation "androidx.compose.runtime:runtime-livedata:1.4.0-alpha04"
  65. // Coroutines
  66. implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
  67. implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
  68. // Coroutine Lifecycle Scopes
  69. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
  70. implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"
  71. // Hilt
  72. implementation "com.google.dagger:hilt-android:2.44"
  73. kapt "com.google.dagger:hilt-compiler:2.44"
  74. }

As I understand it, this error is related to dependencies, but all dependencies were taken from a 10-day-old video. I tried to omit the gradle version, but it didn't work.

答案1

得分: 0

问题实际上是,你已经两次添加了lifecycle-runtime-ktx库,而且它们的版本不同,这可能是原因。

请保留2.5.1版本并移除2.3.1

英文:

Actually the problem is, you have added lifecycle-runtime-ktx library two times and both have different version , may be this will be the reason.

  1. implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"
  2. implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"

keep the 2.5.1 version and remove 2.3.1

答案2

得分: -1

解决问题的方法是添加:

  1. implementation "androidx.navigation:navigation-compose:2.5.1"
  2. implementation "androidx.fragment:fragment-ktx:1.5.2"
英文:

the solution to the problem turned out to be adding

  1. implementation "androidx.navigation:navigation-compose:2.5.1"
  2. implementation "androidx.fragment:fragment-ktx:1.5.2"

huangapple
  • 本文由 发表于 2023年2月24日 17:17:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554686.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定