<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:PMingLiU;
        panose-1:2 2 3 0 0 0 0 0 0 0;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@PMingLiU";
        panose-1:2 2 3 0 0 0 0 0 0 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
pre
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=blue>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Nikos,<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Building for Java in a standard Linux
environment is a little different from building in the<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Android environment.&nbsp; We&#8217;ve used as
a starting point these instructions:<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><a
href="http://trac.osgeo.org/gdal/wiki/BuildingForAndroid">http://trac.osgeo.org/gdal/wiki/BuildingForAndroid</a><o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Though in theory they could be buillt, the
individual stand-alone apps such as gdalinfo<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>must be run from a command line (I
believe) which is lacking in the Android environment, without<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>rooting.&nbsp; Rooting is not presently an
option for me for various administrative reasons.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I&#8217;m actually commenting out the
builds for the stand-alone applications.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>What I&#8217;m really building in this
case is the libgdaljni.so file (along with libjdalconst.so) that can<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>be loaded and executed from an Android activity.&nbsp;
Our libgdaljni.so contains the link results of<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>from libgdal.a, gdal_wrap.o and some
kakadu library routines.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>If there&#8217;s an entry point within the
libgdaljni.so that will perform the equivalent functionality as<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>the stand-alone gdalinfo executable, I
could try that.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Jim P.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> Nikolaos
Hatzopoulos [mailto:nhatzop@gmail.com] <br>
<b><span style='font-weight:bold'>Sent:</span></b> Thursday, August 11, 2011
5:56 PM<br>
<b><span style='font-weight:bold'>To:</span></b> Jim Pendleton<br>
<b><span style='font-weight:bold'>Cc:</span></b> Even Rouault;
gdal-dev@lists.osgeo.org<br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [gdal-dev] SWIG JNI
binding question with GetMetadataItem function</span></font><o:p></o:p></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>Did you follow these
instructions?<br>
<br>
<a href="http://trac.osgeo.org/gdal/wiki/GdalOgrInJavaBuildInstructionsUnix">http://trac.osgeo.org/gdal/wiki/GdalOgrInJavaBuildInstructionsUnix</a><br>
<br>
this command must work:<o:p></o:p></span></font></p>

<pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>java -classpath `pwd`/gdal.jar:`pwd`:`pwd`/build/apps gdalinfo<o:p></o:p></span></font></pre>

<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>as the instruction are
saying:<br>
<i><span style='font-style:italic'>With luck you will see the gdalinfo usage
message. </span></i><br>
<br>
and try to see a gdalinfo of a file<br>
<br>
--Nikos Hatzopoulos<o:p></o:p></span></font></p>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>On Thu, Aug 11, 2011 at 3:21 PM, Jim Pendleton &lt;<a
href="mailto:jimp@ittvis.com">jimp@ittvis.com</a>&gt; wrote:<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
Even,<br>
<br>
Thanks for the suggestion, but if I've implemented your<br>
suggestion properly, it has not solved the underlying problem.<o:p></o:p></span></font></p>

<div>

<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'><br>
&gt;I'm not sure how you've compiled the gdal_warp.cpp, but if you didn't<br>
&gt;use the provided swig/java/GNUmakefile, there's one point you must be<br>
&gt;very careful that is mentionned at the bottom of that makefile :<o:p></o:p></span></font></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>To create a .so file from source in Android, you generally use the<br>
ndk-build utility along with one or more Android.mk and Application.mk<br>
files. &nbsp;I execute the standard make/make install from<br>
within the swig/java directory, then I compile and link gdal_wrap.cpp<br>
within the context of a separate ndk-build process.<br>
<br>
Android NDK Release 6 uses GNU Make 3.81 as its build utility.<br>
<br>
The compiler in my case is arm-linux-androideabi-g++ (GCC) 4.4.3.<br>
<br>
The loader is GNU ld (GNU Binutils) 2.19.<o:p></o:p></span></font></p>

<div>

<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'><br>
&gt;# Do not remove -fno-strict-aliasing while SWIG generates weird code<br>
&gt;in upcast methods<br>
&gt;# See <a href="http://trac.osgeo.org/gdal/changeset/16006" target="_blank">http://trac.osgeo.org/gdal/changeset/16006</a><br>
<br>
&gt;That would be a plausible cause for the crash, since in your<br>
&gt;particular case the GetMetadataItem() method is in the MajorObject<br>
&gt;class, so the Dataset object needs to call the SWIGDatasetUpcast()<br>
&gt;method...<o:p></o:p></span></font></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Indeed I was lacking the -fno-strict-aliasing switch in the C++ flags
in<br>
my<br>
Android.mk file.<br>
<br>
However, I've added this switch to both LOCAL_CFLAGS and LOCAL_CPPFLAGS<br>
for the libgdaljni.so build and I continue to get the error during<br>
execution.<br>
<br>
To add some more info to my original message, the actual error comes<br>
from<br>
within Java_org_gdal_gdal_gdalJNI_MajorObject_1GetMetadataItem_1_1SWIG10<br>
in<br>
gdal_wrap.cpp on the call to jenv-&gt;GetStringUTFChars(jarg2, 0). &nbsp;First
a<br>
JNI<br>
warning is issued, then the access violation appears to occur before<br>
that<br>
function can return, or at least before a debug statement I've added<br>
after<br>
the call can send its output to the Android LogCat output.<br>
<br>
The error that's issued is related to jarg2 which is supposed to be a<br>
jstring, versus the jarg1 argument you mentioned which requires the<br>
upcast to GDALMajorObjectShadow.<br>
<br>
I think I'll need to further debug the pointers that are being passed<br>
down to the *GetMetadataItem*1SWIG10* function. &nbsp;None of them look<br>
outrageous at first glance.<br>
<br>
Again, there's every reason to believe I'm missing something that's<br>
otherwise obvious to the experts so please feel free to continue<br>
sending ideas my way!<o:p></o:p></span></font></p>

<div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
Jim P.<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><o:p></o:p></span></font></p>

</div>

</div>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>