1

I want to implement Room database in my app, but I want to do that by creating a Library project.

Library project will store data Android project will have the Objects and Dao's

Is this possible?

For this I have to implement Room in both Android project as well as Library

But can I have Dao's and Objects in Android project and Database in Library

Why I want to do this. I want to build this feature in a generic way so that it can be used in my other project. Also Library will not just store the data, it will have some offline functionality which read a Offline data table and checks the internet connection and picks data from the table and send it to server.

None of this is implemented yet. I am in the process of thinking what is the right aproach

Thanks for your suggestions

R

BRDroid
  • 3,920
  • 8
  • 65
  • 143
  • Room DB is already a very much abstract enough SQLite **wrapper** library. – Taseer May 28 '20 at 15:39
  • Only reason I want it separate it I will be building offline functionality, which can be used in other app. but i am not sure how to handle Room in library and objects daos in project, not sure if that is even a good idea – BRDroid May 28 '20 at 15:41

2 Answers2

0

It's a great desire to move Room to the separate module as far it's Android specific and violates the principle of the Clean Architecture. Here is where you can start, at least it looks similar: another stack question and take a look at all the answers.

About re-usage, probably, it will be quite hard. Not sure, that time you spend to make it universal be less than when you implement it in each project. So, take the time in the account also.

The case where it makes sense.
At my company, we did the next. We have a few related products (a few apps) that have similar user-intended logic. So we have a library that takes care of all user login / token expiration logic and so on and it provides a simple interface for the app to handle user account. Single code base, useful when fixing bugs. And connect this library to each project as a general module. But still, each app has its own internet communication and database because of domain-specific data.
The best for testing and architecture - move all room and internet logic to the module in the app. Access it by interfaces. You can share that module between apps.

RevakoOA
  • 601
  • 1
  • 9
  • 20
  • yeah makes sense, as db will be more related to he app and its objects it is hard and not valuable to move that to a separate library is what your are suggesting right – BRDroid May 28 '20 at 17:41
-1

I think you can use dynamic feature module, because it dependency to the app module and you can use Dao and Objects from app.

dinhlam
  • 708
  • 3
  • 14
  • can you give any example or links please – BRDroid May 28 '20 at 15:37
  • Here: https://developer.android.com/guide/app-bundle/dynamic-delivery. But if use it, you need to have some config.. – dinhlam May 28 '20 at 15:40
  • but how will that help me? I did not understand. – BRDroid May 28 '20 at 15:41
  • I am not sure it can be use on your case or not, as me know dynamic feature just depend to app module, so you can use somethings declare in your app, but how to config, you can follow above link. – dinhlam May 28 '20 at 15:53