This is an Android app that has a single activity and all that's done in that
activity is load libdatabase.so
and then make some calls through some SWIG-
generated JNI glue code into the native binary.
MainActivity.java
: the sole activity in the Android appbuild_android.sh
: script that can be run to generate SWIG JNI glue code andlibdatabase.so
binaries for all Android architecturesdatabase_swig.i
: interface file that's used by SWIGdatabase.h
: header file that SWIG interface includesdatabase.c
: C code to match that indatabase.h
- libs directory: contains all of the arch-specific
libdatabase.so
binaries - mydatabase directory: contains all of the SWIG-generated JNI glue code
- SWIG generated JNI glue code generated for
%pointer_functions(MyDatabase, MyDatabaseHandle)
results in:
public static SWIGTYPE_p_MyDatabase MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase obj) {
return new SWIGTYPE_p_MyDatabase(databaseJNI.MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase.getCPtr(obj)), true);
}
when really I want something like:
public static MyDatabase MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase obj) {
return new MyDatabase(databaseJNI.MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase.getCPtr(obj)), true);
}
which is what I've manually edited it to in the committed code.
- Unsure how to use the function pointer,
SomeFuncPtr fPtr;
, defined as part ofstruct MyDatabase
.
The SWIG-generated JNI code lets me do:
SWIGTYPE_p_MyDatabase myDBPtr = database.new_database("testing");
MyDatabase myDB = database.MyDatabaseHandle_value(myDBPtr);
myDB.getFPtr("hello"); // doesn't work - says that no arguments are expected
SWIGTYPE_p_f_p_q_const__char__int myFunc = myDB.getFPtr();
myFunc("hello"); // error about "Method call expected"
but both of the calls involving getFPtr
result in an error, as noted in the comments in the code above.