SQLite Forum

Using android AAR with modified sqlite_open_v2() - attach gives problems
I've virtually no experience of working with SQLite at the source level, and none with using it on Android, but with a "generic debugger's hat" on, it seems to me that one of the most likely causes (or, at least, the one to eliminate first before digging deeper) is that your custom `libsqliteX.so` has not been "built properly" in some manner.

Therefore, assuming you've not already done so, I would suggest building `libsqliteX.so` with _no modifications_ to the source. If your app hangs/crashes, then it suggests the build process (or whatever is involved in getting your app to use your custom version of SQLite) is at fault.

If/when an unmodified custom-build works while doing "normal SQLite things", I would then make a small change to the code to "prove beyond doubt" that it is your custom version of SQLite that's being used: perhaps write something to a known file or logcat; make one of the interface-level functions return an easy-to-see-it's-different value. It probably doesn't matter at this stage if it makes SQLite unusable: you're just proving that you can alter the code and see the effects.

Once you _know_ you can customise the normal SQLite code and successfully build and use it from your app the focus switches to whether you're "breaking" SQLite and/or Android in what you're trying to do... I assume [this post by omen_wand](https://sqlite.org/forum/forumpost/2fffd3c4f9) relates to the same problem (if not, the two of you should probably collaborate!).

While I don't know much about the internals of SQLite's code, a phrase from that post "_returns a handle with two attached database connections_" _feels_ like the sort of thing that would be easy to "get wrong": thinking purely off the top of my head, I can imagine that there might be things that happen later in the official `sqlite3_open_v2()` code that mean trying to do the equivalent of `ATTACH` at the point you're doing so means it's never going to work (internal structures haven't been initialised properly, that sort of thing).

Again thinking in a generic-debugger manner, I'd try working though things in stages. Start with a _small_ change to `sqlite3_open_v2()`: perhaps instead of opening the passed-in database file, always open `"test.db"`, or open `"mydb-test.db"` when `"mydb.db"` was passed-in. If that works, try something a little more involved.

If you get to this stage, you probably need someone who _does_ know the innards of SQLite and you probably need to show examples of the changes you're trying to make...