AndroidHowto

jaakla edited this page Jul 6, 2015 · 12 revisions

See http://trac.osgeo.org/gdal/wiki/BuildingForAndroid for basic instructions

Versions known to work:

  • GDAL 1.11 release (tags/1.11)
  • Android NDK v7c

Download stuff and patch guess config

git clone https://github.com/OSGeo/gdal.git
git checkout tags/1.11
cd gdal
rm config.sub config.guess
wget http://git.savannah.gnu.org/cgit/config.git/plain/config.sub
wget http://git.savannah.gnu.org/cgit/config.git/plain/config.guess

Set environment. you need to have toolchain created beforehand

export PATH=/Users/jaak/android-8-toolchain/bin:$PATH
export NDK_ROOT=/Users/jaak/dev/android-ndk-r7b

Build gdal. Note that gif driver did not work, so it is excluded

CFLAGS="-mthumb" CXXFLAGS="-mthumb" LIBS="-lsupc++ -lstdc++"  ./configure --host=arm-linux-androideabi --prefix=/Users/jaak/git/gdal/gdal/external/gdal --without-gif --with-threads --with-ogr  --with-geos --with-libz=internal

for multithread support edit port/cpl_config.h . Needed even if you had --with-threads above

     /* #undef CPL_MULTIPROC_PTHREAD */
     #define CPL_MULTIPROC_PTHREAD 1

remove remapping, edit port/cpl_virtualmem.cpp

-#define HAVE_5ARGS_MREMAP
+// #define HAVE_5ARGS_MREMAP

Following takes some time, could be an hour

make
make install
#-> library is in external/gdal now
#make lib-target
#make install-lib

Generate swig bindings and wrappers

cd swig
make ANDROID=yes
cd java
make ANDROID=yes
cd ../..

copy and build libraries in Android NDK project

cd /Users/jaak/Documents/workspace_mapsdk/play_Android_Samples1/jni
# copy library bin and wrappers:
cp /Users/jaak/git/gdal/gdal/external/gdal/lib/libgdal.a ./
cp /Users/jaak/git/gdal/gdal/external/gdal/include gdal/include

#copy wrappers
cp /Users/jaak/git/gdal/gdal/swig/java/*_wrap.cpp ./
cp /Users/jaak/git/gdal/gdal/swig/java/gdalconst_wrap.c ./

# copy headers
cp -r /Users/jaak/git/gdal/gdal/swig/java/org ../jniwrap/

Create Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := gdal
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/gdal/include
LOCAL_SRC_FILES := libgdal.a
LOCAL_EXPORT_LDLIBS := -lz
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := gdaljni
LOCAL_SRC_FILES := gdal_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := gdalconstjni
LOCAL_SRC_FILES := gdalconst_wrap.c
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := ogrjni
LOCAL_SRC_FILES := ogr_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := osrjni
LOCAL_SRC_FILES := osr_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)

Build NDK part (while in project jni folder)

ndk-build

Result: .so files in NDK project libs/armeabi folder

Repeat this for other native platvorms.

Extra libraries

Expat - needed for KML and some other drivers CURL - for online drivers (wms etc)

  • Download expat sources (e.g. 2.1.0 version), curl sources (e.g. 7.33.0)
  • extract src, configure, make
cd <expat dir>
CFLAGS="-mthumb" CXXFLAGS="-mthumb" LIBS="-lsupc++ -lstdc++"  ./configure --host=arm-linux-androideabi
make

  • add configuration to gdal configure:
cd <gdal dir>
CFLAGS="-mthumb" CXXFLAGS="-mthumb" LIBS="-lsupc++ -lstdc++"  ./configure --host=arm-linux-androideabi --prefix=/Users/jaak/git/gdal/gdal/external/gdal --without-gif --with-threads --with-ogr  --with-geos --with-libz=internal --with-expat=/Users/jaak/Downloads/gdal-curl2-ecwj2-expat/expat-2.1.0/external/expat/
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.