joaoventura / pybridge

Reuse Python code in native Android applications
215 stars 56 forks source link

Cannot use sqlite #13

Closed pbienst closed 6 years ago

pbienst commented 6 years ago

Starting from your template, I made the following modifications:

Added to Android.mk:

# Include libsqlite3.so

include $(CLEAR_VARS)
LOCAL_MODULE    := libsqlite3
LOCAL_SRC_FILES := $(CRYSTAX_PATH)/sources/sqlite/3/libs/$(TARGET_ARCH_ABI)/libsqlite3.so
LOCAL_EXPORT_CFLAGS := -I $(CRYSTAX_PATH)/sources/sqlite/3/include/
include $(PREBUILT_SHARED_LIBRARY)

Running ndk-build resulted in libsqlite3.so showing up in my project.

In bootstrap.py I added some quick-and-dirty test code:

def greet(args):
    """Simple function that greets someone."""
    print(0)
    import sqlite3
    print(1)
    try:
        conn = sqlite3.connect("test.db")
        print(sqlite3.version)
    except Error as e:
        print(e)
    finally:
        conn.close()
    return 'Hello %s' % args['name']

This prints 0 to the log, but then gives

12412-12412/com.jventura.pyapp A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 12412 (.jventura.pyapp)

What am I missing?

Thanks for this great library, BTW!

joaoventura commented 6 years ago

Which permissions are you using? I use sqlite3 in my Charts app, and I've set . Can't remember if it makes a difference, but do try it..

Also, you shouldn't include sqlite3 on your Android.mk. Just copy "_sqlite3.so" from the crystaxndk (from the correct architecture folder) and put it on src/main/assets/python so that the python interpreter can find it when you do "import sqlite3".

Finally, if your example doesn't work, removing everything and check that you can at least import sqlite3 without any errors. Then keep adding things until you find that something may not be working.

pbienst commented 6 years ago

Using _sqlite3.so did the trick, thanks!