SQLite Android issue

SQLite Android issue
0.0 0


Im trying to include an SQL database in my project,

  • I have downloaded and included sqlite.c and .h into my project in Xcode - This works fine on ios
  • On Android my .mk file looks like this
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

$(call import-add-path,$(LOCAL_PATH)/../../../../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../../../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../../../../cocos2d/cocos)
$(call import-add-path,$(LOCAL_PATH)/../../../../../cocos2d/cocos/audio/include)

LOCAL_MODULE := MyGame_shared


LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../../Classes/AppDelegate.cpp \
                   ../../../Classes/HelloWorldScene.cpp \
                   ../../../Classes/sqlite3.c \

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes


LOCAL_STATIC_LIBRARIES := cocos2dx_static



$(call import-module,.)


But when I try to compile my project on android I’m getting tons of errors for example the first few errors

jni/../../../Classes/sqlite3.c:31470:42: error: 'mmap' undeclared here (not in a function)
   { "mmap",         (sqlite3_syscall_ptr)mmap,            0 },
jni/../../../Classes/sqlite3.c:31477:42: error: 'munmap' undeclared here (not in a function)
   { "munmap",       (sqlite3_syscall_ptr)munmap,          0 },
jni/../../../Classes/sqlite3.c:31484:42: error: 'mremap' undeclared here (not in a function)
   { "mremap",       (sqlite3_syscall_ptr)mremap,          0 },

There are hundreds of these errors after and I’m wondering if anybody knows what I am doing wrong?
Or a suggestion to help?


I am not sure if it matters, but you don’t need a \ here since it is the last source file in the list.


Thanks for the reply,
Yes I noticed that but it does not make any difference and every example or anything from sqlite seems to be just include the source so have not a clue whats going on.


actually, I just had a thought. Is your database encrypted?


Sorry yes I want to use encryption so in my application.mk file my flags are


Do i need something more included for the encryption like ssl?


I think you need to use SQLCipher then


This is what im trying to figure out because I set this pre-processor flag in my Xcode project and it builds fine and I can encrypt/decrypt my DB maybe iOS has something built in for the encryption that android does not?


perhaps, I don’t know for sure.

Try following these:

Also, maybe ensure you are using the latest and greatest SQLite version.


Yes have the most up to date SQL version even if i remove the preprocessing flag to set encryption enabled it does not seem to change the errors when compiling I am using

cocos compile -p android --android-studio


I have the same problem. How can i solve? please help.


Error:(30845, 42) error: 'mmap' undeclared here (not in a function)

I included sqlite3.c in “Android.mk”, everything seems ok, but it still gives me this error.

And my database is not encrypted. To be honest, i don’t have a database, i’m trying to create one with code. But I can’t even compile my code, it gives me this error.

EDIT: Ok I solved this problem. Look here https://stackoverflow.com/questions/46384658/bash-script-error-ndk-build

But now I have another SQLite problem, maybe i’ll create a new thread.


are you including sqlcipher anyplace?


I started writing a chapter on SQLite, btw, but it isn’t done yet.

It is WIP here: https://github.com/cocos2d/cocos2d-x-docs/blob/master/en/advanced_topics/sqlite.md