Cannot resolve symbol repeatOnLifecycle in Android - android

I'm following this article to collect flows in UI. But I couldn't resolve repeatOnLifeCycle API in my code. I have added the below dependency, though.
lifecycle:lifecycle-runtime-ktx:2.4.0-alpha03
Please help

It's not
lifecycle:lifecycle-runtime-ktx:2.4.0-alpha03
but
androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-alpha03

I hope this gradle config can help you.
def lifecycle_version = "2.4.0"
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version")
implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version")
implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycle_version")
With this set, i resolve "repeatOnLifecycle" with this import:
import androidx.lifecycle.repeatOnLifecycle

I also had a similar issue. For me, adding the following in the dependencies section of the build.gradle file (the App Module one and not the Project one) helped to resolve the issue:
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-alpha03"
I also removed the import androidx.lifecycle.Lifecycle that was already there in the problematic file and got Android Studio to import the right one just in case the old one was wrong.
Found the latest version number to use(i.e. the "2.4.0-alpha03" part) from the following link but I think Android Studio would have later given a hint on the latest version to upgrade to anyway even if I hadn't done this:
https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-runtime-ktx/2.2.0-alpha01

Note: These APIs are available in the lifecycle:lifecycle-runtime-ktx:2.4.0-alpha01 library or later.
lifecycle-runtime-ktx

for me changing gradle from offline to online somehow solved the problem :/

Related

Didn't find class "java.lang.Math8" on path: DexPathList

After migrating the Gradle version to 7.2, I get this error when running the application.
I noticed that it's pointing to Java 8 date/time feature, LocalDate.
My project already has coreLibraryDesugaringEnabled = true enabled.
After lots of searches without any result, I noticed only a simple solution as updating the coreLibraryDesugaring version will solve the problem. upgrading from 1.1.1 to 1.1.5.
Hope this saves you some time!
Can confirm that Amir's answer solved this for me. Under dependencies, bump to this: coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

Why can not I import 'androidx.core.app.NotificationChannelCompat'?

I am using androidx.core.app.NotificationChannel and androidx.core.app.NotificationChannelCompat to resovle the android compatible problem according to (Androidx API reference)[https://developer.android.google.cn/reference/androidx/core/app/NotificationChannelCompat].
But even I add implementation "androidx.core:core:1.3.1 in my build.gradle file, Android Studio prompts me can not resovle symbole NotificationChannelCompat.
Why? I do not want use SDK version conditional statements to fill my source code.
It'll resolve NotificationChannelCompat if you change:
implementation "androidx.core:core:1.3.2"
to
implementation "androidx.core:core:1.5.0-alpha04"
Latest versions: https://developer.android.com/jetpack/androidx/releases/core
Here is the commit, it was missing :-) https://android-review.googlesource.com/c/platform/frameworks/support/+/1360061

RxSearchView not supporting androidx SearchView?

I've migrated my project to androidx. When i use RxSearchView it results in an error
RxSearchView.queryTextChanges(searchView).
Type mismatch.
Required:
android.widget.SearchView
Found:
androidx.appcompat.widget.SearchView
I was facing this problem recently and was able to fix it by using this explicit dependency: implementation 'com.jakewharton.rxbinding3:rxbinding-appcompat:3.0.0-alpha2'.
You can find this dependency and some other ones at Github RxBinding.
I hope I was not too late and I hope this helps!
Edit
I know I responded this not long ago but something messed up the library. 3.0.0-alpha is no longer the latest release and has been replaced with version 3.0.0 of which I no longer find RxSearchView anywhere, not even on the alpha version.
Edit 2
Since I never found RxSearchView again, I had to implement an OnQueryTextListener myself, following a pretty cool tutorial I found here. It uses Kotlin's new coroutines and works as fine as RxSearchview.
If you update your dependency to the rxbinding3, version 3.0.0 by adding the following line in your app's build.gradle:
implementation 'com.jakewharton.rxbinding3:rxbinding-appcompat:3.0.0'
Then you should be fine by simply using the new API adapted to the Kotlin style:
Replace your code where it has
RxSearchView.queryTextChangeEvents(searchView)
to
searchView.queryTextChangeEvents()
Also keep in mind that the return value typed as SearchViewQueryTextEvent uses property access, so things like it.queryText() should be changed to it.queryText.

Why is Algolia Client not resolved in android studio?

I don't know why android studio is not able to resolve Client and Query from the import statements:
import com.algolia.search.saas.Client;
import com.algolia.search.saas.Query;
It is showing cannot resolve Client and Query on the both import statements.
This is present in my app Gradle file:
implementation 'com.algolia:instantsearch-android:1.15.0'
I tried invalidating caches and restart multiple times and even tried to change the version of Algolia dependency in Gradle file above, but nothing worked.
I am not able to understand why is this happening, I would appreciate if someone could help me in this.
try this:
https://www.algolia.com/doc/guides/building-search-ui/installation/android/
dependencies {
// [...]
implementation 'com.algolia:instantsearch-android:1.+'
// This will automatically update to the latest v1 release of InstantSearch
// OR
implementation 'com.algolia:algoliasearch-android:3.+'
// This will automatically update to the latest v3 release of the client
}
try including this also
implementation 'com.algolia:instantsearch-androidx-core:1.15.2'
I'm using the androidx libraries so your mileage may vary, but adding
implementation 'com.algolia:algoliasearch-android:3.27.0'
resolved the problem for me.

Android Studio 3.x: error: cannot find symbol class GlideApp

I updated Android Studio from 2.x to 3.x last week end. The project migration was perfect, build was great. And now, from 2 hours, I can't explain why, I can't build, I have this error on Glide now:
Error:(26, 22) error: cannot find symbol class GlideApp
All was good before, I didn't change anything (gradle or configuration), and now this error appears...
For information about Glide, in my Gradle:
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC1'
compile 'com.github.bumptech.glide:glide:4.0.0-RC1'
compile 'com.github.bumptech.glide:okhttp3-integration:4.0.0-RC1'
The GlideApp file is generated automatically (I checked it).
So, it's a crazy situation. Thank you very much guys!
Some of these situations tend to pop up from time to time (for an instance with the generated class R, where it ends up not being generated). The easiest way I have solved this in the past is to clean the project and rebuild it. And if that doesn't work, press File in the top menu and press "Invalidate caches and restart". A second popup will appear, press "Invalidate caches and restart". It may take a while as Android Studio needs to re-index and rebuild the project, but it solves most issues I have had.
The same happened to me and it was one of weirdest errors I ever got,
I used Butterknife in my project and I found out that if you define the views in private mode, you get this error
use:
#BindView(R.id.tv_option_one)
TextView tv_option_one;
#BindView(R.id.tv_option_two)
TextView tv_option_two;
instead of
#BindView(R.id.tv_option_one)
private TextView tv_option_one;
#BindView(R.id.tv_option_two)
private TextView tv_option_two;
it mostly happens when Butterknife can't find the view when you use bindView or the onClick annotation, and the worst part is that it shows errors everywhere except the place where they should be.
I ran into the same problem when I migrated to AndroidX. I ended up solving it by adding/updating the dependencies to
implementation 'com.github.bumptech.glide:glide:4.8.0-SNAPSHOT'
kapt 'com.github.bumptech.glide:compiler:4.8.0-SNAPSHOT'
kapt 'androidx.annotation:annotation:1.0.0-rc01'
This also happens when you have another error in your code. Gradle doesn't get to generate Glide classes since another error is thrown before it
Glide 4.x introduces some breaking changes. Be sure to follow the instructions in the Download & Setup page of Glide docs.
Do not neglect the changes in proguard.cfg. After changes, rebuild your project and you should be able to access GlideApp.
add those dependencies like so
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
In my case, I forgot to apply kapt plugin, So I just added it to my module-level build.gradle.
apply plugin: 'kotlin-kapt'
You can find more details about it - Glide Docs
I have picked up this problem when a sub-package uses GlideApp with AppGlideModule being extended in a class one level up in the package hierarchy.
I suspect that the compiler tries to compile the sub-package classes before generating GlipeApp.
My solution was to extend AppGlideModule in a separate module and then add it as a dependency to all the modules using GlideApp.
If you are using DI, you could try comment out GlideApp error code, then rebuild. IDE should you where the error truly is.
I got the solution of this issue.
Build -> Clean project (After) Rebuild Project
Then after you will able to import the GlideApp in your project
For Reference
https://github.com/bumptech/glide/issues/1945
For me, the problem was that there was a different import error (which was a "valid" error, I had indeed deleted the referenced method).
But because I got like 20 messages that GlideApp can't be found when building the app, I didn't even notice that there was such an error.
After correcting that error and rebuilding the project, everything worked normally again.
Generation of the following class worked for me:
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
#GlideModule
public final class MyAppGlideModule extends AppGlideModule {
// Dummy. Needed to generate GlideApp. See:
// GlideApp.with(service).
}

Categories

Resources