I get this error if I do any of the following upgrades:
androidx.fragment:fragment-ktx:1.6.0-alpha04 -> alpha05
androidx.appcompat:appcompat:1.7.0-alpha01 -> alpha02
androidx.navigation:navigation-...- ktx:2.6.0-alpha04 -> alpha05
For reference I have these dependencies:
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
where lifecycle_version is 2.5.1
Use myData.map {}or myData.switchMap
Have a look at this
Related
Simply adding a TextField to a composable in Android causes a NoSuchFieldError when executing. The application works perfectly fine when I remove the TextField (the application does not contain another TextField so far).
I think it might be a dependency issue (hence the dependencies below). But I am at my wits end. What is happening?
I have already tried to invalidate cache and restart, as well as clean and rebuild the application.
Code:
TextField(
value = "text",
onValueChange = {
}
)
Error:
java.lang.NoSuchFieldError: No static field $stable of type I in class Landroidx/compose/foundation/text/KeyboardActions; or its superclasses (declaration of 'androidx.compose.foundation.text.KeyboardActions' appears in /data/app/~~uEpWT9N7xCnbk8jjsQk_yg==/xx.xxx.xxx.dev-Q5085dpAd5iQ0tK6W7b8rA==/base.apk)
at androidx.compose.material.TextFieldKt.TextField(TextField.kt:207)
Dependencies:
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation "androidx.compose.ui:ui:1.3.3"
implementation "androidx.compose.material:material:1.3.1"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:1.3.3"
implementation "androidx.navigation:navigation-compose:2.5.3"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'
implementation 'androidx.paging:paging-common-ktx:3.1.1'
implementation "androidx.paging:paging-compose:1.0.0-alpha17"
implementation "com.google.accompanist:accompanist-systemuicontroller:0.29.0-alpha"
implementation "org.jetbrains.lets-plot:lets-plot-kotlin:3.0.0"
implementation "androidx.room:room-runtime:2.5.0"
implementation "androidx.room:room-paging:2.5.0"
annotationProcessor "androidx.room:room-compiler:2.5.0"
kapt "androidx.room:room-compiler:2.5.0"
testImplementation 'junit:junit:5.8.1'
testImplementation "io.mockk:mockk:1.13.4"
testImplementation 'org.junit.jupiter:junit-jupiter'
debugImplementation "androidx.compose.ui:ui-tooling:1.3.3"
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation "io.insert-koin:koin-android:3.2.0"
implementation "io.insert-koin:koin-androidx-compose:3.2.0"
}
Your accompanist version does not match the compose UI version.
As you can see in this page, if you use compose UI 1.3.X you should use accompanist 0.28.0
I just updated the compose version to 1.0.0‑beta07, and its showing this run time error
No interface method startRestartGroup(ILjava/lang/String;)Landroidx/compose/runtime/Composer; in class Landroidx/compose/runtime/Composer; or its super classes (declaration of 'androidx.compose.runtime.Composer'
....
at com.google.accompanist.coil.CoilImage__CoilKt.CoilImage(Coil.kt:245)
at com.google.accompanist.coil.CoilImage.CoilImage(Coil.kt:1)
below is my gradle dependencies file
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.compose.compiler:compiler:$compose_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.runtime:runtime:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation 'androidx.activity:activity-compose:1.3.0-alpha08'
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha05"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation "io.coil-kt:coil-gif:1.2.1"
implementation "io.coil-kt:coil-svg:1.2.1"
implementation "com.google.accompanist:accompanist-coil:0.6.2"
and version compose_version = '1.0.0-beta07'
Every library needs to be recompiled against beta07 to work, as per the Compose release notes:
Note: Libraries dependent on Compose will need to recompile with version 1.0.0‑beta07. Otherwise, libraries may encounter a NoSuchMethodError, such as:
java.lang.NoSuchMethodError: No interface method startReplaceableGroup(ILjava/lang/String;)V in class Landroidx/compose/runtime/Composer; or its super classes. (Ia34e6)
In your case you have to update the accompanist libraries with the 0.10.0.
Change:
implementation "com.google.accompanist:accompanist-coil:0.6.2"
to
implementation "com.google.accompanist:accompanist-coil:0.10.0"
Coil, Glide and Image Loading Core have been removed
After being deprecated in v0.14.0, it's time to remove the coil, glide and imageloading-core libraries. Some discussion about this can be seen on the Kotlin Slack: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1627482619344000. the recommendation is to move to https://coil-kt.github.io/coil/compose/
So Change ;
implementation "com.google.accompanist:accompanist-coil:0.6.2"
to
implementation("io.coil-kt:coil-compose:1.3.2")
Also;
CoilImage removed too, you can use;
Image(
painter = rememberImagePainter("https://www.example.com/image.jpg"),
contentDescription = null,
modifier = Modifier.size(128.dp)
)
Make sure that all your compose libraries are all using the same version 1.0.0-beta07. That should resolve your issue.
Here are my dependencies:
//Room and Lifecycle Libraries
kapt "androidx.room:room-compiler:2.2.0-alpha02"
kapt 'androidx.room:room-compiler:2.2.0-alpha02'
kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha03"
implementation "androidx.room:room-runtime:2.2.0-alpha02"
implementation 'androidx.room:room-runtime:2.2.0-alpha02'
implementation "androidx.lifecycle:lifecycle-viewmodel:2.2.0-alpha03"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-alpha03"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha03"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha03"
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
As you can see, I implemented the final versions and yet I do not have access to the liveData builder. How can I fix this?
From the documentation:
For liveData, use androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha01 or higher.
So you're just missing the dependency:
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03"
Build fails with error "cannot find symbol DataBindingComponent" in all generated binding classes.If I remove the room compiler dependency from my module gradle, then it unable to find room db at run time saying "Db_Impl does not exist".
def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
//kapt "android.arch.persistence.room:compiler:$room_version"
//kapt 'com.android.databinding:compiler:3.2.1'
dependencies {
def room_version = "2.1.0-alpha06"
implementation "androidx.room:room-runtime:1.1.1"
annotationProcessor "androidx.room:room-compiler:1.1.1" // For Kotlin use kapt instead of annotationProcessor
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:1.1.1"
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:1.1.1"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:1.1.1"
// Test helpers
testImplementation "androidx.room:room-testing:1.1.1"
}
Try this..
add this dependency into app level gradle file.
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
more information refer this link
https://www.simplifiedcoding.net/android-room-database-example/
You are missing kotlin's annotation processor plugin. Add this to the top of your app level gradle file
apply plugin: 'kotlin-kapt'
and uncomment the data binding dependency. Sync after this.
For Java project, in order to recognize android.arch.lifecycle.ViewModelProviders, I simply define the following in my build gradle
Java project
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
def lifecycle_version = "1.1.1"
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
// alternately - if using Java8, use the following instead of compiler
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
However, in Kotlin project, I can hardly make it recognizes android.arch.lifecycle.ViewModelProviders. I tried
Kotlin project
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
def lifecycle_version = "1.1.1"
// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
kapt "android.arch.lifecycle:compiler:$lifecycle_version"
It is still not able to recognize android.arch.lifecycle.ViewModelProviders
The complete build.gradle is as follow - https://github.com/yccheok/AndroidDraw/blob/748baf44571c5b83d0c6e5b6a7137eef9cb17cdc/app/build.gradle
May I know, is there anything else I had missed out?
Using kapt you should also apply plugin: 'kotlin-kapt'.
Please try this, Change in your viewmodel and extension version '1.1.0'
def lifecycle_version = "1.1.0" // change in this line
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version"
Note : I have also using this kind of error message, but my problem was solved when I downgrade version 1.1.1 with version 1.1.0.
You need to check downgrade your version number.
Please try this :
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.0,0'
implementation 'androidx.lifecycle:lifecycle-livedata:2.0.0'
This is what I am using right now as I converted to androidX.
Hope this helps.
In my case I also need to remove from gradle.properties these lines:
android.useAndroidX=true
android.enableJetifier=true
I know the question was asked previously when it was not deprecated but for other developer's info. The Class has been deprecated and now you can directly user ViewModelProvider with constructor only.
For Further Info Android Developer