SerializedName is an unresolved reference throughout Android project, gets resolve when building - android

Everywhere in my project I see that the annotation #SerializedName is unresolved, even though I import it:
import com.google.gson.annotations.SerializedName
I also have all the necessary build.gradle dependencies:
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.6.2"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
implementation 'com.google.code.gson:gson:2.8.6'
I've synced project files and rebuilt multiple times, but the annotation keeps getting highlighted in red by Android Studio.
The oddest part is that everything compiles, builds and works perfectly, but having all the red elements makes working on the project difficult, what could I be missing?

Just upgrade to
implementation 'com.google.code.gson:gson:2.8.8'
You can find the latest version on Github releases

retrofit and gson should have same same version to work well
inorder to work well in build.gradle(:app)
implementation 'com.squareup.retrofit2:retrofit:2.9.1'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'com.squareup.retrofit2:converter-gson:2.9.1'

Related

Android studio Error: To use RxJava2 features, you must add `rxjava2` artifact from Room as a dependency

I have facing the following error while building the project. And unable to solve the same after trying it for whole day.
error: To use RxJava2 features, you must add `rxjava2` artifact from Room as a dependency. androidx.room:room-rxjava2:<version>
public abstract java.lang.Object clearAllBillers(#org.jetbrains.annotations.NotNull()
^
below are my dependancies inside the build.gradle
implementation("androidx.room:room-rxjava2:2.3.0")
implementation "androidx.room:room-runtime:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
kapt "androidx.room:room-compiler:2.3.0"
I have done trying already existing solutions such as upgrading
classpath 'com.android.tools.build:gradle:7.3.1'
Also tried to do invalidate cache and clean project.
Still not able to solve the issue.
Please help me if you have any idea to get it resolve.
Thanks in advance!!!❤️
Not sure why haven't you received an answer quicker (because this question has an easy solution)
you just need to add
implementation("androidx.room:room-rxjava2:2.4.3")
to your build.gradle (for your app or module)
(source)

Hilt (Android): cannot find symbol return DaggerApp_HiltComponents_ApplicationC.builder()

I tried to replace Koin with Hilt (bad idea) for DI and now I'm stuck with this error:
Hilt_App.java:21: error: cannot find symbol
return DaggerApp_HiltComponents_ApplicationC.builder()
^
symbol: variable DaggerApp_HiltComponents_ApplicationC
What is it? How to fix it?
I got the same error message.
My problem was that I had an old/deprecated gradle dependency.
Make sure to remove following dpenedency from your gradle file:
/* DELETE this dependency */
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
If you are working on a modular project, take care of dependencies!
For example, if you have a retrofit dependency in your data module, even your data module implemented in the app module, you must add retrofit dependency as well or make them transactive with the api to be accessible to the app module.
For those who had the same error but did not miss any dependencies. I had this problem, because I forgot to annotate one class with "#Inject constructor". After I did that, everything worked again.
as answered in the guestion comments. The problem was that when using Jetpack integrations as explained here for the ViewModels https://developer.android.com/training/dependency-injection/hilt-jetpack and you have to add those dependencies also in the main app module (not only in the modules where you actually use ViewModels).
for example , if you have the following in the feature module's build.gradle file:
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_lifecycle"
kapt "androidx.hilt:hilt-compiler:1.0.0-alpha02"
make sure you add them to the app's build.gradle file as well
I've met the issue and work with these dependencies:
implementation "com.google.dagger:hilt-android:$hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$hiltVersion"
kapt "androidx.hilt:hilt-compiler:$hiltAndroidXVersion"
https://medium.com/gradeup/dependency-injection-dagger-hilt-vs-koin-ab2f7f85e6c6

androidx.lifecycle.DefaultLifecycleObserver not found

I am having a problem where my build cannot find one of the androidx classes, specifically:
androidx.lifecycle.DefaultLifecycleObserver
Here are my gradle deps:
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
I don't have any other problems getting androidx classes, just this one.
I have tried to invalidate caches in android studio and restart with no luck. Also a build clean as well as a gradle sync.
I verified here:
https://developer.android.com/jetpack/androidx/migrate
The mapping of that class from the support library to androidx:
android.arch.lifecycle.DefaultLifecycleObserver ->
androidx.lifecycle.DefaultLifecycleObserver
Any ideas on why this is happening?
I think that's because you're missing one dependency:
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
Get the latest version of lifecycle-common-java8 here
See the documentation:
If you use Java 8 Language, then observe events with
DefaultLifecycleObserver. To include it you should add
"androidx.lifecycle:lifecycle-common-java8:" to your
build.gradle file.

Error: cannot find symbol class DaggerAppComponent

I downloaded several sample projects from github that use dagger, e. g. Moxy sample project (trying to run github-sample) but everywhere there is the same error - «cannot find symbol class DaggerAppComponent». I did not make any changes in the projects just downloaded and tried to run them.
Gradle version - 3.1.2
AndroidStudio – 3.3
def dagger = '2.7'
implementation "com.google.dagger:dagger:$dagger"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger"
Does anybody has an idea how to fix it?
Adding the below dependency.
implementation 'com.google.dagger:dagger:2.x'
annotationProcessor 'com.google.dagger:dagger-compiler:2.x'
OR try this
annotationProcessor 'com.google.dagger:dagger-compiler:2.12'
This may not be directly related to what the original poster was looking for but posting this answer for anyone looking to solve a similar error. If you have converted some of your classes to Kotlin then use kapt instead of annotationProcessor in your build.gradle. It is kind of obvious looking back but took me a while to figure out why I'm getting the sysmbol not found error with DaggerAppComponenent without any other details.

Android Studio: Play Services libraries (GCM & Maps) unresolved (errors) but project is working correctly

I'm working on a project. I started with updating the libraries after not touching the project for around a year or so. Updated most of the libraries except implementation 'com.google.android.gms:play-services-maps:9.2.1' and implementation 'com.google.android.gms:play-services-gcm:9.2.1' because there is an older version of a library supplying push for me, which I can't update right now. Anyways, after a while I opened some classes and noticed that for example SupportMapFragment is red and says "Unresolved reference". This happens with every class that comes out of the two libraries. However, the project still runs and still works as expected.
Why is this happening? And how can I fix it?
I will list some other libraries which could have an influence below:
$support_library_version = '27.1.0'
implementation "com.android.support:appcompat-v7:$support_library_version"
implementation "com.android.support:recyclerview-v7:$support_library_version"
implementation "com.android.support:cardview-v7:$support_library_version"
implementation "com.android.support:design:$support_library_version"
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.1#aar') {
transitive = true;
}
They got updated from these versions:
$support_library_version = '24.1.1'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.picasso:picasso:2.5.2'
Crashlytics was not added in previous versions
I was experiencing a similar issue earlier today and used the instructions from this post to fix it:
File->Invalidate Caches/Restart
In addition, it appears that Gradle 3.1.0 doesn't work, but Gradle 2.3.0 does.
Apparently the version I had for GCM and maps was too low. I had to update to a higher version and the unresolved references disappeared. I'm using 11.8.0 right now.

Categories

Resources