thomaskioko/android-liveData-viewModel

Dagger circular dependency while adding recursive model

Sunkari16 opened this issue · 1 comments

Update the movie model to contain a parent movie object and code stopped compiling with the below

app:javaPreCompileDebug UP-TO-DATE
/Users/hari/Manch/android-liveData-viewModel/app/src/main/java/com/thomaskioko/livedatademo/di/AppInjector.java:11: error: cannot find symbol
import com.thomaskioko.livedatademo.di.component.DaggerAppComponent;
                                                ^
  symbol:   class DaggerAppComponent
  location: package com.thomaskioko.livedatademo.di.component
warning: Supported source version 'RELEASE_7' from annotation processor 'android.arch.lifecycle.LifecycleProcessor' less than -source '1.8'
warning: Supported source version 'RELEASE_7' from annotation processor 'android.arch.persistence.room.RoomProcessor' less than -source '1.8'
/Users/hari/Manch/android-liveData-viewModel/app/src/main/java/com/thomaskioko/livedatademo/db/entity/Movie.java:48: error: Cannot figure out how to save this field into database. You can consider adding a type converter for it.
    public Movie parent;
                 ^
/Users/hari/Manch/android-liveData-viewModel/app/src/main/java/com/thomaskioko/livedatademo/db/TmdbDb.java:17: warning: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide `room.schemaLocation` annotation processor argument OR set exportSchema to false.
public abstract class TmdbDb extends RoomDatabase {
                ^
/Users/hari/Manch/android-liveData-viewModel/app/src/main/java/com/thomaskioko/livedatademo/di/component/AppComponent.java:24: error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public interface AppComponent {
       ^
3 errors
3 warnings
:app:compileDebugJavaWithJavac FAILED

Updated Model


@Entity(indices = {@Index("id")},
        primaryKeys = {"id"})
@TypeConverters(TmdbTypeConverters.class)
public class Movie {
    @SerializedName("id")
    @Expose
    @NonNull
    public final int id;
    @SerializedName(value = "poster_path")
    public String posterUrl;
    public Double rating;
    @SerializedName(value = "release_date")
    public String releaseYear;
    public String title;
    public Boolean adult;
    public String overview;
    @SerializedName(value = "original_title")
    public String originalTitle;
    @SerializedName(value = "original_language")
    public String originalLanguage;
    @SerializedName(value = "backdrop_path")
    public String backdropPath;
    public Double popularity;
    @SerializedName(value = "vote_count")
    public Integer voteCount;
    public Boolean video;
    @SerializedName(value = "vote_average")
    public Double voteAverage;
    @SerializedName(value = "genre_ids")
    public List<Integer> genreIds;

    @SerializedName(value = "parent")
    public Movie parent;

    public Movie(int id, String posterUrl, Double rating, String releaseYear, String title, Boolean adult,
                 String overview, String originalTitle, String originalLanguage, String backdropPath,
                 Double popularity, Integer voteCount, Boolean video, Double voteAverage, List<Integer> genreIds, Movie parent) {
        this.id = id;
        this.posterUrl = posterUrl;
        this.rating = rating;
        this.releaseYear = releaseYear;
        this.title = title;
        this.adult = adult;
        this.overview = overview;
        this.originalLanguage = originalLanguage;
        this.originalTitle = originalTitle;
        this.backdropPath = backdropPath;
        this.popularity = popularity;
        this.voteCount = voteCount;
        this.video = video;
        this.voteAverage = voteAverage;
        this.genreIds = genreIds;
        this.parent = parent;
    }
}

Would be great of you if you can let me know how to go about this issue.
Have tried with stack over flow and other places but could find a solution or may be I was not able to get it right.

Found the issue, the issue seemed to be with the Rooms db not being able to convert the model, had to write a type converter. The Error from dagger is a by product of that.