Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to compile for Android use? #18

Closed
lshAndroid opened this issue Dec 2, 2017 · 6 comments
Closed

How to compile for Android use? #18

lshAndroid opened this issue Dec 2, 2017 · 6 comments
Labels

Comments

@lshAndroid
Copy link

How to compile for Android use? Not through Cocos2dx framework to use, direct jni call method to make the encrypted database into a decrypted database? Ask for help, Thanks.

@utelle utelle added the question label Dec 2, 2017
@utelle
Copy link
Owner

utelle commented Dec 2, 2017

Unfortunately, I have no experience with developing for Android, so I can't give you much advice how to solve your issue.

However, the SQLite Android documentation might give you some hints. Especially, read the section about SEE - SQlite Encryption Extension, since the encryption extension coming with wxSQLite3 uses the same SQLite API as SEE. Instead of the source file sqlite3.c just reference the source file sqlite3secure.c in the build files. Depending on your needs you may have to add compiler defines to enable additional SQLite features.

Good luck!

@Willena
Copy link

Willena commented Dec 2, 2017

Hi @lshAndroid !
Why not using Java with android ?
In the past I have managed to rebuild the jdbc driver in order to include the sqlite library included in this project. You can find it here : https://github.com/Willena/sqlite-jdbc-crypt/releases

I have not yet updated the repo with the lastest version. The version for the moment is 3.18.0.
It'is not JNI only but can be usefull.

Good luck !

@iamcxl369
Copy link

iamcxl369 commented Dec 18, 2017

Hi @lshAndroid !

Below is the process about how to use wxSqlite on android.

0x01. compiling sqlite3.c

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE:= libsqlite3

LOCAL_SRC_FILES:= sqlite3secure.c 

include $(BUILD_STATIC_LIBRARY)

0x02. write your jni code use wxsqlite

#LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
    TestNative.cpp
LOCAL_MODULE := TestNative

LOCAL_LDLIBS := -llog -landroid 
LOCAL_STATIC_LIBRARIES := libsqlite3 
include $(BUILD_SHARED_LIBRARY)

the wxSqlite interface same with sqlite3.
TestNative.cpp:

void Java_com_iamcxl_wwww_wxsqlite3_MainActivity_cryptSqlite3Test(){
    LOGI("cryptSqlite3Test() >>>>>>\n");
    const char * sSQL;
    char * pErrMsg = 0;
    int ret = 0;
    sqlite3 * db = 0;

    ret = sqlite3_open("/storage/sdcard0/xxx.db", &db); // create a database
    
    ret = sqlite3_key_v2( db, "", "abcdefghijklmnopqrstuvwxyz", 26 ); //set the database password

    sSQL = "create table xxx(name varchar(20), student);";
    sqlite3_exec( db, sSQL, _callback_exec, 0, &pErrMsg ); //create the table

    sSQL = "insert into class values('name', 'iamcxl369');";
    sqlite3_exec( db, sSQL, _callback_exec_insert, 0, &pErrMsg ); // insert data to database

    sSQL = "select * from xxx;";
    sqlite3_exec( db, sSQL, _callback_exec_select, 0, &pErrMsg ); // query data from database

    ret =  sqlite3_rekey_v2( db, "", NULL, 0 ); // remove the password

    sqlite3_close_v2(db);  // close the db
    db = 0;
    LOGI("cryptSqlite3Test() <<<<<<\n");
}

@utelle
Copy link
Owner

utelle commented Jan 29, 2018

Since @iamcxl369 described in detail, how to use the wxSQLite3 encryption extension in Android applications, I'm going to close this issue.

@utelle utelle closed this as completed Jan 29, 2018
@malcolmjerry
Copy link

malcolmjerry commented May 22, 2023

Download SQLite3MultipleCiphers,
https://github.com/utelle/SQLite3MultipleCiphers

Open /build/sqlite3mc_vc17.sln by visual studio 2022, then build sql3mc_dll.

Create a jni folder, create Android.mk , paste the content

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= sqlite3
LOCAL_MODULE_FILENAME := sqlite3
LOCAL_SRC_FILES:= sqlite3mc.c
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_C_INCLUDES := $(LOCAL_PATH)
include $(BUILD_SHARED_LIBRARY)

COPY and paste all source file into jni folder. (copy from SQLite3MultipleCiphers/src)

No need to cd jni , just keep current directory.

Run "ndk-build" (before this , you must have downloaded the ndk and added it to your environment PATH)

Put /libs/arm64-v8a and /libs/armeabi-v7a into /Assets/Plugins/Android (For Unity3d)

Change the method name :
1.

    //[DllImport( "sqlite3", EntryPoint = "wxsqlite3_config" )]
    //internal static extern int wxsqlite3_config( IntPtr db, string param, int newValue );

To this

      [DllImport( "sqlite3", EntryPoint = "sqlite3mc_config" )]
      internal static extern int sqlite3mc_config( IntPtr db, string param, int newValue );
//[DllImport( "sqlite3", EntryPoint = "wxsqlite3_config_cipher" )]
//internal static extern int wxsqlite3_config_cipher( IntPtr db, string cipherName, string paramName, int newValue );

To this

   [DllImport( "sqlite3", EntryPoint = "sqlite3mc_config_cipher" )]
   internal static extern int sqlite3mc_config_cipher( IntPtr db, string cipherName, string paramName, int newValue );

Everything works now!

@utelle
Copy link
Owner

utelle commented May 22, 2023

My project SQLite3 Multiple Ciphers started with version 1.3.7 to provide pre-compiled binaries for Android (see latest release). These binaries are built following the installation guide that can be found on the official SQLite Android Bindings web page. Detailed instructions how to build the Android bindings on your own can be found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants