Are there any good database abstraction layers/object relational mappers/ActiveRecord implementations/whatever they are called for Android? I'm aware that db4o is officially supported, but it has quite a large footprint and I'd rather use a more conventional database (SQLite
).

- 16,194
- 20
- 64
- 81

- 251
- 1
- 3
- 3
-
12I'm going to encourage you to stay as close to the "metal" as possible. Most of these devices are not like servers, where you can throw serious horsepower at these endless layers of abstraction. These devices are not powerful and every method call you do has both a performance hit and a battery hit. You need to be thinking about how to accomplish the most with the least amount of hoops to jump through. Adding an abstraction layer isn't going to do anything but slow your application down and just burn more battery doing the same thing some basic SQL would accomplish. – MattC Dec 03 '09 at 20:37
-
+1 to MattC. With limited power and battery life to keep in mind, I really think you want to stay away from ORM tools on Android. – Erich Douglass Dec 04 '09 at 23:16
-
db4o wouldn't continuously support Android if the footprint was unacceptable... – L̲̳o̲̳̳n̲̳̳g̲̳̳p̲̳o̲̳̳k̲̳̳e̲̳̳ Sep 03 '10 at 02:40
-
possible duplicate of [Any good ORM tools for Android development?](http://stackoverflow.com/questions/371538/any-good-orm-tools-for-android-development) – user Sep 18 '13 at 13:26
12 Answers
I am the main author of ORMLite which was designed to be small[ish] but still provide higher level functionality. ORMLite makes calls to the native Android OS database APIs to support its ORM functionality. See the following for general information
Here are some Android example applications:

- 115,027
- 24
- 293
- 354
-
I recently starting developing my own lightweight wrapper for Android's SQLite interface. I had several goals: no need for autogenerated code, no cumbersome interfaces or abstract base classes, using annotations to mark up arbitrary beans, and a simple interface: something as simple as calling one method on a helper class to persist or load a DAO. The Android interface wound up getting in the way for this and I had to scrap the high level design I started. ORMLite looks like it is not a perfect fit for my requirements, but so far it looks really good. I recommend checking it out. – Mar 05 '11 at 22:11
-
Let me know what it's missing John. More Android feedback on the user mailing list would be helpful. – Gray Mar 07 '11 at 13:40
-
@John can you provide a link for this "lightweight wrapper" you developed?? Thanks – Otto Apr 20 '11 at 16:10
-
@Otto - I had it partially coded but scrapped it. I checked and apparently I deleted it entirely, sorry. @Gray - My priorities have shifted to this "real world" thing for a bit, but when I get back to Android development I'm definitely checking out ORMLite again. If I find something I need that it lacks, I'll get involved somehow: submit a patch, post on the mailing list, whatever is appropriate. – Apr 23 '11 at 00:38
I tried the Sugar ORM, which is very basic (and easy to use) but it worked for my needs.

- 621
- 4
- 14
-
1do you know of any comparison between it and other alternatives? maybe a benchmark ? i want to know how well it works so that it won't slow down the app too much. – android developer Feb 20 '14 at 12:07
-
Nope, but if you are looking for performance I would suggest to use it on non-performance critical places and either use direct access to the database or write helper methods on domain classes. I am thinking on something like Person.findAllByCityAndAge(String city, int age) {some performance tested code, not necessary using Sugar} – enTropy Feb 20 '14 at 17:00
-
How did you handle database changes? How do you notify "observers" that they should update themselves? Similar to Loaders, which aren't usable here? – Martin Melka Aug 21 '15 at 07:54
Try ActiveAndroid. It is free and open source (Apache Version 2.0).
From the website:
ActiveAndroid is an active record style ORM (object relational mapper). [...] ActiveAndroid allows you to save and retrieve SQLite database records without ever writing a single SQL statement. Each database record is wrapped neatly into a class with methods like save() and delete().
[...] Accessing the database is a hassle, to say the least, in Android. ActiveAndroid takes care of all the setup and messy stuff, and all with just a few simple steps of configuration.

- 27,862
- 20
- 113
- 121

- 2,590
- 3
- 24
- 33
There is an 'android-active-record' project which provides ActiveRecord abstraction for accessing Android SQLite database. It's available here: http://code.google.com/p/android-active-record
It allows to eliminate most of boilerplate coding when performing CRUD operations on database entities and also minimizes efforts for creating/maintaining a database structure

- 5,237
- 6
- 39
- 50
Shameless plug, but I've been working on a new open source Android framework called Infinitum. One of its main features is an ORM which has a criteria API similar to Hibernate and a few other nifty features (associations, lazy loading, etc.). It's still in its early stages, but I think it's coming along pretty nicely.

- 14,640
- 15
- 80
- 115
I have written a new ORM, for android, that's aimed and being as easy as possible to implement. It support lists and SQL free migration a couple things which I always found had an overhead in other libraries.

- 1,141
- 11
- 13
If performance and size matter, you should have a look at our open source ORM tool greenDAO. We wrote it because we did not want to compromise on speed. Other tools heavily rely on reflection, which is very slow on Android. Despite the tiny size (<100k), it supports relations, query builders, etc.

- 6,950
- 31
- 52
There's also Neodatis and Perst (Lite).
I've toyed with Perst a year ago and concluded it's not worth it.
After all, a) Android runs on a rather restricted device with ~16mb of heap space per app and b) You customers would really appreciate performance and low power consumption.
So my advice is to go with SQLite and hand-written SQL. It's not hard at all and the wrappers provided by Android SDK are really nice.
EDIT: In 2012 the advice would be to use the ORM component of DroidParts (which is my project).

- 56,576
- 33
- 147
- 165
I faced the same problem and looked at both android-active-record and ActiveAndroid. I found android-active-record didn't handle the things I cared about (relationships for example), and ActiveAndroid isn't free. Therefore, I decided to write my own library. It's called AndroidRecord and it's hosted on GitHub and you're free to do with it what you want (I think I'm going to go with the MIT license). I use this every day and I'm content with it, but I'd love to get feedback.
If you need to know how to use it, I'm working on the documentation. If you need it right away, you can check out this lame example project which should be enough to dip your toes in. You can also email me of course.

- 1,163
- 2
- 13
- 21
Have a look at Androrm. It is open source and well documented (see here). If you ever worked with django, you will notice, that the syntax is very similar.
Androrm also supports abstraction classes for the most common field types, plus relational fields. This way it enables you to query for your data in an very easy manner with only very little effort on your side.

- 27,862
- 20
- 113
- 121

- 623
- 1
- 7
- 17
SQLite is explicitly part of Android:
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
However you might have to create your own abstraction layer (query builder for simple queries), or otherwise deal with SQL.
Maybe http://developer.android.com/reference/android/database/sqlite/SQLiteQueryBuilder.html is what you need?

- 17,476
- 5
- 50
- 60
-
I know there's SQLite built in to Android: what I am looking for is something more high-level. – user222469 Dec 03 '09 at 19:55