[gdal-dev] SWIG JNI binding question with GetMetadataItem function

Jim Pendleton jimp at ittvis.com
Thu Aug 11 18:21:27 EDT 2011


Thanks for the suggestion, but if I've implemented your
suggestion properly, it has not solved the underlying problem.

>I'm not sure how you've compiled the gdal_warp.cpp, but if you didn't
>use the provided swig/java/GNUmakefile, there's one point you must be
>very careful that is mentionned at the bottom of that makefile :

To create a .so file from source in Android, you generally use the
ndk-build utility along with one or more Android.mk and Application.mk
files.  I execute the standard make/make install from 
within the swig/java directory, then I compile and link gdal_wrap.cpp 
within the context of a separate ndk-build process.

Android NDK Release 6 uses GNU Make 3.81 as its build utility.

The compiler in my case is arm-linux-androideabi-g++ (GCC) 4.4.3.

The loader is GNU ld (GNU Binutils) 2.19.

># Do not remove -fno-strict-aliasing while SWIG generates weird code
>in upcast methods
># See http://trac.osgeo.org/gdal/changeset/16006

>That would be a plausible cause for the crash, since in your
>particular case the GetMetadataItem() method is in the MajorObject
>class, so the Dataset object needs to call the SWIGDatasetUpcast()

Indeed I was lacking the -fno-strict-aliasing switch in the C++ flags in
Android.mk file.

However, I've added this switch to both LOCAL_CFLAGS and LOCAL_CPPFLAGS 
for the libgdaljni.so build and I continue to get the error during 

To add some more info to my original message, the actual error comes
within Java_org_gdal_gdal_gdalJNI_MajorObject_1GetMetadataItem_1_1SWIG10
gdal_wrap.cpp on the call to jenv->GetStringUTFChars(jarg2, 0).  First a
warning is issued, then the access violation appears to occur before
function can return, or at least before a debug statement I've added
the call can send its output to the Android LogCat output. 

The error that's issued is related to jarg2 which is supposed to be a
jstring, versus the jarg1 argument you mentioned which requires the
upcast to GDALMajorObjectShadow.

I think I'll need to further debug the pointers that are being passed
down to the *GetMetadataItem*1SWIG10* function.  None of them look 
outrageous at first glance.

Again, there's every reason to believe I'm missing something that's
otherwise obvious to the experts so please feel free to continue
sending ideas my way!

Jim P.

More information about the gdal-dev mailing list