I connected the external library as a module.

There is an object in the main app module.

I need to use an instance of this object in the connected module. But the connected module does not know anything about this object. I can’t just add a dependency with this object to the gradle , because a circular dependency is formed (what the IDE warns about) and errors pour in hail.

How to solve this problem?

Real example:

Object in app :

 public class FoodUnitDate { @SerializedName("date") private String dateString; @SerializedName("first_api") @Expose private float firstApi; @SerializedName("second_api") @Expose private float secondApi; } 

Which I can't just create and transfer to lib , the lib doesn't know about it. I have to create the same model in lib and write in the main module:

  com.applikeysolutions.cosmocalendar.model.FoodUnitDate foodUnitDate = new com.applikeysolutions.cosmocalendar.model.FoodUnitDate(); 

Then fill it with data from my FoodUnitDate (which is in the app ) and transfer it to the object from lib , + when I return, I will have to parse it back from the external model to my own.

I am sure that this is the most crooked approach, especially considering that thundering objects fall under such crutches, whose parameters are other objects. Help get rid of it.

  • The idea is to have some kind of core module that describes all the models that will be used by all or some of the modules. Then the app depends on the core, your someModule depends on the core, the profit. Problems may arise when models start to differ in different modules ... - Yura Ivanov

1 answer 1

On the advice of Yura Ivanov began to use a separate module for models. It is quite simple and convenient, especially when the project is swelling.