Sunday, March 13, 2016

How much Android Non-Promoted Apps Earn?

UPDATED part of article begins "UPDATE"  section below.

This article will be short and straight to what a developer must know. If you come across articles like “how I earned millions and blah blah” then in many cases they are doing their marketing only. In business many people don't want to create competitors for free and one making such money will not make noise every place like spammer. Most people publish such articles just to attract people do some affiliate marketing, get visits/installs or sell their contents by making you dream high.


When one says “some of our people earn millions” truly means only some of them earn. Some can even be only one. What this article is about? Well by seeing the figures you can judge yourself how much real money comes even after publishing 5-10+ apps with ads. I came to see even much more poor stats for paid apps.

Lets look at the stats, screen-shot of Adsense Mobile app -










This is screen-shot of income from 5+ apps in total. Looking at stats you might feel how disastrous the income is? You are right, it is disastrous to shut down anyone's career. I used to make 200x than this in Nokia Ovi store. I will not disclosure the exact links of apps and detailed income report.


The screen-shot shows LifeTime 27,709 Ads shown in screen and made $47+. Great thing is that this will still be deducted when Google will take 30% of this and then US government will deduct taxes and Indian Government will deduct taxes. I have rough estimate that will result in total real income in hand ~$20-25. With this anyone can buy 1+ Birthday cakes. So what do you think where is the problem? It is not in Ads. It is in lesser number of downloads. So how much is less? Let me tell how much these apps got producing above income. Out of ~8 apps 4 didn't got any downloads to be shared here. Without giving names I am sharing stats: Puzzle Game - ~950 Downloads in 3yrs. Action Game - ~6000 downloads in 9 months. App 1 - ~250 downloads in 2yrs. 3 Apps launched in December 2015 - < 50 downloads (Were utilities like Fake SMS, Notification tool etc). Some more apps recently launched which have crossed 100+ downloads in less time with zero promotion.



At present all downloads I get are from organic users by nearly zero promotion. I don't have enough money for promotion. Most apps don't even cross 50 downloads in months. I was talking about how much daily downloads is less. Well I am sharing how much do I get then you take average of how much these numbers make money. Last year I was getting around ~80 downloads daily for my Bestial Kungfu game. It used to make ~$0.2+ daily. Today all apps get 30-100 daily downloads and earn always less than ~$0.2.

If they get downloaded 100x more then income becomes $20 daily. That means 500+ daily downloads are absolute minimum. Rest calculation is up to you. I can give one important tip which is its useless to make lots of apps. Quantity will not work. I tried making FakeSMS, Gallery, Notification tool, File Monitoring app, runner 2d games, 3d games like Temple Run, 3D tools etc. This article does not means there is no money. I know many are making great money from very simple apps. What really matters is timing. If some app is not there it can be you to build it. I am working on those apps and focusing on website more than before.



UPDATE

I have got more stats to share. My app imagesizereducer. From past 2-3 months gets 500+ downloads daily. Sometimes 750+. From all apps i get ~1000 downloads a day. I use Banner ads on above app and users mostly come from Asia. The daily income is still not USD 1 a day. Sometimes it goes 1+ but on average its not even $1.








Saturday, March 12, 2016

Compiling GraphicsMagick (1.3.23) using Android NDK

Compiling GraphicsMagick (1.3.23) using Android NDK


Before starting read this common guide how to build libpng with Android NDK  for most of 
building process as it will be re-writing of same stuff if I write here as well.

After above guide understood and ensured the NDK and other tools are correctly setup.
Follow these step to build GraphicsMagick 1.3.23.
 

Setup:
  • Create directory GM and extract GraphicsMagick 1.3.23 contents inside it. Go inside extracted GM directory.
  • Create directories "prefix" and "dependencies". Instead of prefix you can give names like bin, binaries etc.
  • Copy lib****.a files in GM/dependencies directory. libjasper.a liblzma.a libtiff.a libfreetype.a libjpeg.a libpng.a libwebp.a. If you don't have these libraries then with help of above libpng, webp, FreeType etc guide you can make them.
  • Create GM/dependencies/include directory and copy APIs i.e. headers from all above libraries inside it.
Below is the script to build GraphicsMagick. It does not build c++ apis.


Android Script

# AndroidBuild.sh START
#!/bin/sh
# http://www.ourinnovativemind.in
# http://www.gamesgreh.in

# use custom build environment
export DEPENDENCIES="`pwd`/dependencies"
export INC_DEPENDENCIES=${DEPENDENCIES}/include
export INC_JPEG=${INC_DEPENDENCIES}/jpeg
export INC_PNG=${INC_DEPENDENCIES}/png
export INC_TIFF=${INC_DEPENDENCIES}/tiff
export INC_WEBP=${INC_DEPENDENCIES}/webp
export INC_TTF=${INC_DEPENDENCIES}/ttf
export INC_JASPER=${INC_DEPENDENCIES}/jasper
export INC_LZMA=${INC_DEPENDENCIES}/lzma


export EXTRA_INCLUDES="-I${INC_DEPENDENCIES} -I${INC_JPEG} -I${INC_PNG} -I${INC_TIFF} -I${INC_WEBP} -I${INC_TTF} -I${INC_JASPER} -I${INC_LZMA}"
export EXTRA_LIBS=$DEPENDENCIES


export CONFIGURATION_OPTIONS="--disable-largefile --disable-openmp --without-magick-plus-plus --disable-installed --without-threads --without-x --without-perl --disable-shared --without-gslib"



# use custom build environment

# installation directory
export PREFIX="`pwd`/prefix"

# Path of NDK. For simplicity make symlinks in home directories
export NDK=/home/bindesh/bin/ndk

# processor specific libraries and includes.
# Suffix for arch-???. arch-arm  arch-arm64  arch-mips  arch-mips64  arch-x86  arch-x86_64
export ARCH=arm

# compiler for processor
export CROSS_COMPILE=arm-linux-androideabi

# Android platform version
export PLATFORM=android-8

# GCC compiler version
export GCC_VERSION=4.8


# Getting toolchain directory inside NDK from variables set above
# Hardcoded for linux running on x86 cpu 64-Bit
export ANDROID_PREFIX="${NDK}/toolchains/$CROSS_COMPILE-$GCC_VERSION/prebuilt/linux-x86_64"

# SYSROOT. usr dir i.e. usr/include, usr/lib
export SYSROOT="${NDK}/platforms/$PLATFORM/arch-$ARCH"
export CROSS_PATH="${ANDROID_PREFIX}/bin/${CROSS_COMPILE}"

# Some compiler and binutils. More might be needed depending on source. 
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib

# for C++ extra libs
export CXX_SYSROOT=${NDK}/sources/cxx-stl/gnu-libstdc++/${COMPILER_VERSION}  # standard template library
export CXX_BITS_INCLUDE=${CXX_SYSROOT}/libs/armeabi/include

export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig


# Flags for compiler
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include ${EXTRA_INCLUDES}"
export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib -L${EXTRA_LIBS}"


./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} "$@" $CONFIGURATION_OPTIONS
make
make install
# AndroidBuild.sh END


Copy all lines above and paste in a new file AndroidBuild.sh and save. Then change the 
variables valid for your system. Create folder prefix or whatever name you like. 
Change NDK variable and compiler related values as per your system.
This script copied from web can cause error due to removal of newlines for strange reasons.
Ensure # is ahead of comments. 
 Now run sh AndroidBuild.sh. It should end without errors. This will install all built files
in prefix directory. Now we can copy libpng16.a renamed to libpng.a and headers directory.


Links:

Script file
http://txt.do/5ns57 or http://textuploader.com/5ns57

Friday, March 11, 2016

Compiling ImageMagick (6.9.3-2) with Android NDK

In this post i am sharing script and configuration to build ImageMagick-6.9.3-2 for Android.

I used ImageMagick source from GIT link to build my own image converter. I made app as i wanted a very simple & straight image converter with desired features. I will timely update this app which you can get from here:

https://play.google.com/store/apps/details?id=org.greh.kisimageconverter


Before starting take a look at this guide "how to build libpng using Android NDK" which describes my OS, NDK and other tools versions.

Setup:
  • Create directory IM and extract ImageMagick-6.9.3-2 package contents inside it. Go inside extracted ImageMagick (IM) directory.
  • Create directories "prefix" and "dependencies"
  • Copy lib****.a files in IM/dependencies directory. libjasper.a liblzma.a libtiff.a libfreetype.a libjpeg.a libpng.a libwebp.a. The libpng guide above is example of how to build these libraries if you don't have them. libjasper is actually not used and is replaced by OpenJpeg/OpenJP2 as i encountered. But to keep script compatible to lower versions of IM i keep this as it is.
  • Create IM/dependencies/include directory and copy APIs i.e. headers from all above libraries inside it.


Contents as reported by directory listing ls -AR command is dumped at end of this post :


Create a shell script "AndroidBuild.sh" in IM directory with contents from below link. This script does not builds c++ API.

Android NDK Linux Build Script:
http://txt.do/5ve04 Or http://textuploader.com/5ve04


Or copy script from below (can be buggy due to corruption of newlines of script due to blog editor):



#!/bin/sh
# http://www.ourinnovativemind.in
# http://www.gamesgreh.in

# use custom build environment
export DEPENDENCIES="`pwd`/dependencies"
export INC_DEPENDENCIES=${DEPENDENCIES}/include
export INC_JPEG=${INC_DEPENDENCIES}/jpeg
export INC_PNG=${INC_DEPENDENCIES}/png
export INC_TIFF=${INC_DEPENDENCIES}/tiff
export INC_WEBP=${INC_DEPENDENCIES}/webp
export INC_TTF=${INC_DEPENDENCIES}/ttf
export INC_JASPER=${INC_DEPENDENCIES}/jasper
export INC_LZMA=${INC_DEPENDENCIES}/lzma


EXTRA_INCLUDES="-I${INC_DEPENDENCIES} -I${INC_JPEG} -I${INC_PNG} -I${INC_TIFF} -I${INC_WEBP} -I${INC_TTF} -I${INC_JASPER} -I${INC_LZMA}"
EXTRA_LIBS=$DEPENDENCIES


export CONFIGURATION_OPTIONS="--disable-installed --disable-largefile --disable-openmp --enable-static --disable-shared --disable-deprecated --disable-docs --without-threads --without-dps --with-gslib --without-freetype --without-fontconfig --without-fpx --without-magick-plus-plus --without-x --without-perl --without-pango --enable-zero-configuration"



# use custom build environment

# installation directory
export PREFIX="`pwd`/prefix"

# Path of NDK. For simplicity make symlinks in home directories
export NDK=/home/bindesh/bin/ndk

# processor specific libraries and includes.
# Suffix for arch-???. arch-arm  arch-arm64  arch-mips  arch-mips64  arch-x86  arch-x86_64
export ARCH=arm

# compiler for processor
export CROSS_COMPILE=arm-linux-androideabi

# Android platform version
export PLATFORM=android-8

# GCC compiler version
export GCC_VERSION=4.8


# Getting toolchain directory inside NDK from variables set above
# Hardcoded for linux running on x86 cpu 64-Bit
export ANDROID_PREFIX="${NDK}/toolchains/$CROSS_COMPILE-$GCC_VERSION/prebuilt/linux-x86_64"

# SYSROOT. usr dir i.e. usr/include, usr/lib
export SYSROOT="${NDK}/platforms/$PLATFORM/arch-$ARCH"
export CROSS_PATH="${ANDROID_PREFIX}/bin/${CROSS_COMPILE}"

# Some compiler and binutils. More might be needed depending on source.
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib

# for C++ extra libs
export CXX_SYSROOT=${NDK}/sources/cxx-stl/gnu-libstdc++/${COMPILER_VERSION}  # standard template library
export CXX_BITS_INCLUDE=${CXX_SYSROOT}/libs/armeabi/include

export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig


# Flags for compiler
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include ${EXTRA_INCLUDES}"
export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib -L${EXTRA_LIBS}"


./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} "$@" $CONFIGURATION_OPTIONS
make
make install





IMPORTANT:
If there are errors of undefined reference then check the config.log file whether the library file names and the library -l parameters use the same name. e.g. we have libpng.a but IM configure script is looking for libpng16.a via -lpng16. Rename the library or pass library as parameter from script.


After all is set well execute the script from inside IM directory. It will create and copy binary files in prefix directory. I could package the prebuilt prefix folder but its size for one type of cpu build is 99MB total without any dependencies files and ImageMagick source.  Whereas libMagickCore-6.Q16.a is 6.4MB and libMagickWand-6.Q16.a is 2.4MB. config.log itself is 1MB!. These size are still without some dependencies like FreeType, Tiff. I didn't fixed them yet.



Contents of prefix folder:

ls -RA
.:
bin  etc  include  lib  share

./bin:
animate    conjure  identify       MagickCore-config  montage
compare    convert  import         MagickWand-config  stream
composite  display  Magick-config  mogrify            Wand-config

./etc:
ImageMagick-6

./etc/ImageMagick-6:
coder.xml      magic.xml               thresholds.xml        type.xml
colors.xml     mime.xml                type-dejavu.xml
delegates.xml  policy.xml              type-ghostscript.xml
log.xml        quantization-table.xml  type-windows.xml

./include:
ImageMagick-6

./include/ImageMagick-6:
magick  wand

./include/ImageMagick-6/magick:
accelerate.h  distort.h            magick.h            resize.h
animate.h     distribute-cache.h   magick-type.h       resource_.h
annotate.h    draw.h               matrix.h            segment.h
api.h         effect.h             memory_.h           semaphore.h
artifact.h    enhance.h            method-attribute.h  shear.h
attribute.h   exception.h          methods.h           signature.h
blob.h        feature.h            mime.h              splay-tree.h
cache.h       fourier.h            module.h            statistic.h
cache-view.h  fx.h                 monitor.h           stream.h
channel.h     gem.h                montage.h           string_.h
cipher.h      geometry.h           morphology.h        studio.h
client.h      hashmap.h            opencl.h            threshold.h
coder.h       histogram.h          option.h            timer.h
color.h       identify.h           paint.h             token.h
colormap.h    image.h              pixel-accessor.h    transform.h
colorspace.h  ImageMagick.h        pixel.h             type.h
compare.h     image-view.h         policy.h            utility.h
composite.h   layer.h              prepress.h          version.h
compress.h    list.h               profile.h           vision.h
configure.h   locale_.h            property.h          widget.h
constitute.h  log.h                quantize.h          xml-tree.h
decorate.h    magic.h              quantum.h           xwindow.h
delegate.h    magick-baseconfig.h  random_.h
deprecate.h   magick-config.h      registry.h
display.h     MagickCore.h         resample.h

./include/ImageMagick-6/wand:
animate.h    deprecate.h     magick-image.h     method-attribute.h  stream.h
compare.h    display.h       magick-property.h  mogrify.h           wand-view.h
composite.h  drawing-wand.h  magick_wand.h      montage.h
conjure.h    identify.h      magick-wand.h      pixel-iterator.h
convert.h    import.h        MagickWand.h       pixel-wand.h

./lib:
ImageMagick-6.9.3      libMagickCore-6.Q16.la  libMagickWand-6.Q16.la
libMagickCore-6.Q16.a  libMagickWand-6.Q16.a   pkgconfig

./lib/ImageMagick-6.9.3:
config-Q16

./lib/ImageMagick-6.9.3/config-Q16:
configure.xml

./lib/pkgconfig:
ImageMagick-6.Q16.pc  MagickCore-6.Q16.pc  MagickWand-6.Q16.pc  Wand-6.Q16.pc
ImageMagick.pc        MagickCore.pc        MagickWand.pc        Wand.pc

./share:
ImageMagick-6

./share/ImageMagick-6:
english.xml  francais.xml  locale.xml








Contents of dependencies folder:


ls -RA
.:
include        libjasper.a  liblzma.a  libtiff.a
libfreetype.a  libjpeg.a    libpng.a   libwebp.a

./include:
jasper  jpeg  lzma  png  tiff  ttf  webp

./include/jasper:
jas_cm.h         jas_fix.h     jas_malloc.h  jas_string.h   Makefile
jas_config2.h    jas_getopt.h  jas_math.h    jas_tmr.h      Makefile.am
jas_config.h     jas_icc.h     jasper.h      jas_tvp.h      Makefile.in
jas_config.h.in  jas_image.h   jas_seq.h     jas_types.h    stamp-h1
jas_debug.h      jas_init.h    jas_stream.h  jas_version.h

./include/jpeg:
cderror.h  jconfig.h  jerror.h    jmemsys.h   jpegint.h  jversion.h
cdjpeg.h   jdct.h     jinclude.h  jmorecfg.h  jpeglib.h  transupp.h

./include/lzma:
lzma  lzma.h

./include/lzma/lzma:
base.h   check.h      filter.h    index_hash.h    version.h
bcj.h    container.h  hardware.h  lzma12.h        vli.h
block.h  delta.h      index.h     stream_flags.h

./include/png:
config.h   pngdebug.h  pnginfo.h     pngpriv.h
pngconf.h  png.h       pnglibconf.h  pngstruct.h

./include/tiff:
t4.h             tif_config.wince.h  tiffconf.h        tiff.h     tiffvers.h
tif_config.h     tif_dir.h           tiffconf.vc.h     tiffio.h   tif_predict.h
tif_config.vc.h  tif_fax3.h          tiffconf.wince.h  tiffiop.h  uvcode.h

./include/ttf:
freetype  ft2build.h

./include/ttf/freetype:
config        ftcid.h     ftincrem.h  ftotval.h   ftsystem.h  tttables.h
freetype.h    fterrdef.h  ftlcdfil.h  ftoutln.h   fttrigon.h  tttags.h
ftadvanc.h    fterrors.h  ftlist.h    ftpfr.h     fttypes.h   ttunpat.h
ftbbox.h      ftgasp.h    ftlzw.h     ftrender.h  ftwinfnt.h
ftbdf.h       ftglyph.h   ftmac.h     ftsizes.h   ftxf86.h
ftbitmap.h    ftgxval.h   ftmm.h      ftsnames.h  internal
ftcache.h     ftgzip.h    ftmodapi.h  ftstroke.h  t1tables.h
ftchapters.h  ftimage.h   ftmoderr.h  ftsynth.h   ttnameid.h

./include/ttf/freetype/config:
ftconfig.h  ftheader.h  ftmodule.h  ftoption.h  ftstdlib.h

./include/ttf/freetype/internal:
autohint.h  ftdriver.h  ftobjs.h   ftserv.h    ftvalid.h   psaux.h    sfnt.h
ftcalc.h    ftgloadr.h  ftpic.h    ftstream.h  internal.h  pshints.h  t1types.h
ftdebug.h   ftmemory.h  ftrfork.h  fttrace.h   pcftypes.h  services   tttypes.h

./include/ttf/freetype/internal/services:
svbdf.h     svgxval.h  svotval.h   svpscmap.h  svttcmap.h  svwinfnt.h
svcid.h     svkern.h   svpfr.h     svpsinfo.h  svtteng.h   svxf86nm.h
svgldict.h  svmm.h     svpostnm.h  svsfnt.h    svttglyf.h

./include/webp:
decode.h  demux.h  encode.h  format_constants.h  mux.h  mux_types.h  types.h 


Building webp library (libwebp-0.4.4) using Android NDK

My setup:
  • OpenSuse Linux Leap 42.1.20151028 x86_64 (64Bit), AMD Athlon X2
  • Android NDK r10e­rc4 (64­bit). Directory name android­ndk­r10e­linux
  • Terminal / Bash shell. On Windows one needs to install binutils, development environment. Just install CodeBlocks windows or other such compiler. They contain most of needed tools.

The title of this post can also be "compile libwebp-0.4.4.tar.gz without Android Studio or without Eclipse". Compile library using ndk-build without android project.


To compile a jni code Android NDK requires a layout of files. We will blind NDK to believe there is an android project and it will compile. Since libwebp (atleast 0.4.4) already contains Android.mk its very easy to compile it.

To create blind NDK assuming there is Android project follow these steps:
  • Create a directory webp. Create jni directory inside it. Extract libweb inside jni. path to libweb Android. mk must be webp/jni/libwebp-0.4.4/Android.mk
  • Create Android.mk & Application.mk files inside jni.
  • Create AndroidManifest.xml above jni directory.


Contents of files:


webp/jni/Android.mk

include  $(call all-subdir-makefiles)


webp/jni/Application.mk

APP_ABI := armeabi-v7a
APP_PLATFORM := android-8
APP_OPTIM := release




webp/AndroidManifest.xml
File content is saved in linked file due to xml getting stripped in this blog.

Link: http://txt.do/5vik0 or http://textuploader.com/5vik0 




Building:
Ensure you have NDK in path environment. It means you can run ndk-build without giving full path. If not then add it in path variable Or simply run /fullpath/ndk-build script from webp/ directory. it will start building webp.


After build is complete the binary files are copied into webp/libs and webp/obj/local. libwebp.a is present in obj/local/armeabi-v7a directory.



Below is the log from my system:


bindesh@linux-k2zc:/mnt/work/work/programming/Android/00_libraries/libwebp/libwebp-0.4.4> ndk-build
[armeabi-v7a] Compile thumb  : cwebp <= cwebp.c
[armeabi-v7a] Compile thumb  : cwebp <= jpegdec.c
[armeabi-v7a] Compile thumb  : cwebp <= metadata.c
[armeabi-v7a] Compile thumb  : cwebp <= pngdec.c
[armeabi-v7a] Compile thumb  : cwebp <= tiffdec.c
[armeabi-v7a] Compile thumb  : cwebp <= webpdec.c
[armeabi-v7a] Compile thumb  : example_util <= example_util.c
[armeabi-v7a] StaticLibrary  : libexample_util.a
[armeabi-v7a] Compile arm    : webp <= enc.c
[armeabi-v7a] Compile arm    : webp <= enc_avx2.c
[armeabi-v7a] Compile arm    : webp <= enc_mips32.c
[armeabi-v7a] Compile arm    : webp <= enc_neon.c
[armeabi-v7a] Compile arm    : webp <= enc_sse2.c
[armeabi-v7a] Compile arm    : webp <= alpha.c
[armeabi-v7a] Compile arm    : webp <= analysis.c
[armeabi-v7a] Compile arm    : webp <= backward_references.c
[armeabi-v7a] Compile arm    : webp <= config.c
[armeabi-v7a] Compile arm    : webp <= cost.c
[armeabi-v7a] Compile arm    : webp <= filter.c
[armeabi-v7a] Compile arm    : webp <= frame.c
[armeabi-v7a] Compile arm    : webp <= histogram.c
[armeabi-v7a] Compile arm    : webp <= iterator.c
[armeabi-v7a] Compile arm    : webp <= picture.c
[armeabi-v7a] Compile arm    : webp <= picture_csp.c
[armeabi-v7a] Compile arm    : webp <= picture_psnr.c
[armeabi-v7a] Compile arm    : webp <= picture_rescale.c
[armeabi-v7a] Compile arm    : webp <= picture_tools.c
[armeabi-v7a] Compile arm    : webp <= quant.c
[armeabi-v7a] Compile arm    : webp <= syntax.c
[armeabi-v7a] Compile arm    : webp <= token.c
[armeabi-v7a] Compile arm    : webp <= tree.c
[armeabi-v7a] Compile arm    : webp <= vp8l.c
[armeabi-v7a] Compile arm    : webp <= webpenc.c
[armeabi-v7a] Compile arm    : webp <= bit_writer.c
[armeabi-v7a] Compile arm    : webp <= huffman_encode.c
[armeabi-v7a] Compile arm    : webp <= quant_levels.c
[armeabi-v7a] StaticLibrary  : libwebp.a
[armeabi-v7a] Compile thumb  : cpufeatures <= cpu-features.c
[armeabi-v7a] StaticLibrary  : libcpufeatures.a
[armeabi-v7a] Compile arm    : webpdecoder_static <= alpha.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= buffer.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= frame.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= idec.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= io.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= quant.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= tree.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= vp8.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= vp8l.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= webp.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= alpha_processing.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= alpha_processing_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= cpu.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec_clip_tables.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec_mips32.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec_neon.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= lossless.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= lossless_mips32.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= lossless_neon.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= lossless_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= upsampling.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= upsampling_neon.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= upsampling_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= yuv.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= yuv_mips32.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= yuv_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= bit_reader.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= color_cache.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= filters.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= huffman.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= quant_levels_dec.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= random.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= rescaler.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= thread.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= utils.c
[armeabi-v7a] StaticLibrary  : libwebpdecoder_static.a
[armeabi-v7a] Executable     : cwebp
[armeabi-v7a] Install        : cwebp => libs/armeabi-v7a/cwebp
[armeabi-v7a] Compile thumb  : dwebp <= dwebp.c
[armeabi-v7a] Executable     : dwebp
[armeabi-v7a] Install        : dwebp => libs/armeabi-v7a/dwebp
[armeabi-v7a] Compile thumb  : webpmux_example <= webpmux.c
[armeabi-v7a] Compile arm    : webpmux <= muxedit.c
[armeabi-v7a] Compile arm    : webpmux <= muxinternal.c
[armeabi-v7a] Compile arm    : webpmux <= muxread.c
[armeabi-v7a] StaticLibrary  : libwebpmux.a
[armeabi-v7a] Executable     : webpmux_example
[armeabi-v7a] Install        : webpmux_example => libs/armeabi-v7a/webpmux_example

Compiling FreeType (2.6.3) using Android NDK.

My setup:

  • OpenSuse Linux Leap 42.1.20151028 x86_64 (64Bit), AMD Athlon X2
  • Android NDK r10e-rc4 (64-bit). Directory name android-ndk-r10e-linux
  • Terminal / Bash shell. On Windows one needs to install binutils, development environment. Just install CodeBlocks windows or other such compiler. They contain most of needed tools.


Before starting please read setup and brief of how libpng is compiled. It is a waste if I write same thing repeatedly.

Link: http://www.ourinnovativemind.in/2016/03/how-to-compile-libpng-using-android-ndk.html


Starting steps same as libpng project:
  • Download Android NDK and extract/install to a path without containing space or special characters. If using Linux then make symbolic link to home.
  • Download FreeType package version 2.6.3
  • Create a working directory where package will be compiled. Extract package.


# AndroidBuild.sh START

#!/bin/sh
# http://www.ourinnovativemind.in
# http://www.gamesgreh.in

# Add configure options here
export CONFIGURATION_OPTIONS="--enable-static --disable-shared --with-bzip2=no"

# use custom build environment

# installation directory
export PREFIX=`pwd`/prefix

# Path of NDK. For simplicity make symlinks in home directories
export NDK=/mnt/work/SDK_IDE/android-ndk-r10e-linux/

# processor specific libraries and includes.
# Suffix for arch-???. arch-arm arch-arm64 arch-mips arch-mips64 arch-x86 arch-x86_64
export ARCH=arm

# compiler for processor
export CROSS_COMPILE=arm-linux-androideabi

# Android platform version
export PLATFORM=android-8

# GCC compiler version
export GCC_VERSION=4.8


# Getting toolchain directory inside NDK from variables set above
# Hardcoded for linux running on x86 cpu 64-Bit
export ANDROID_PREFIX=${NDK}/toolchains/$CROSS_COMPILE-$GCC_VERSION/prebuilt/linux-x86_64

# SYSROOT. usr dir i.e. usr/include, usr/lib
export SYSROOT=${NDK}/platforms/$PLATFORM/arch-$ARCH
export CROSS_PATH=${ANDROID_PREFIX}/bin/${CROSS_COMPILE}

# Some compiler and binutils. More might be needed depending on source.
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib

# package configuration file save location
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig

# Flags for compiler
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include"
export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"

#$@
./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} "$@" $CONFIGURATION_OPTIONS
make
make install

# AndroidBuild.sh END








Copy all lines above and paste in a new file AndroidBuild.sh and save. Then change the variables valid for your system. Create folder prefix or whatever name you like. Change NDK=/mnt/work/SDK_IDE/android-ndk-r10e-linux/ and compiler related values as per your system. This script copied from web can cause error due to removal of newlines for strange reasons. Ensure # is ahead of comments. Now run sh AndroidBuild.sh. It should end without errors. This will install all built files in prefix directory.

Links:
Script file http://txt.do/5vi0z or http://textuploader.com/5vi0z!



Below is output of console if you want to compare it with yours:





bindesh@linux-k2zc:/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3> sh AndroidBuild.sh

FreeType build system -- automatic system detection

The following settings are used:

platform unix
compiler /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
configuration directory ./builds/unix
configuration rules ./builds/unix/unix.mk

If this does not correspond to your system or settings please remove the file
`config.mk' from this directory then read the INSTALL file for help.

Otherwise, simply type `make' again to build the library,
or `make refdoc' to build the API reference (this needs python >= 2.6).

cd builds/unix; \
./configure '--host=arm-linux-androideabi' '--with-sysroot=/mnt/work/SDK_IDE/android-ndk-r10e-linux//platforms/android-8/arch-arm' '--prefix=/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix' '--enable-static' '--disable-shared' '--with-bzip2=no'
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-unknown-linux-androideabi
checking for arm-linux-androideabi-gcc... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc accepts -g... yes
checking for /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-cpp
checking for arm-linux-androideabi-pkg-config... no
checking for pkg-config... /usr/bin/pkg-config
configure: WARNING: using cross tools not prefixed with host triplet
checking pkg-config is at least version 0.24... yes
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld
checking if the linker (/mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm
checking the name lister (/mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to arm-unknown-linux-androideabi format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld option to reload object files... -r
checking for arm-linux-androideabi-objdump... no
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for arm-linux-androideabi-dlltool... no
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for arm-linux-androideabi-ar... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
checking for archiver @FILE support... @
checking for arm-linux-androideabi-strip... no
checking for strip... strip
checking for arm-linux-androideabi-ranlib... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib
checking for gawk... gawk
checking command to parse /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm output from /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc object... ok
checking for sysroot... /mnt/work/SDK_IDE/android-ndk-r10e-linux//platforms/android-8/arch-arm
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for arm-linux-androideabi-mt... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc supports -fno-rtti -fno-exceptions... no
checking for /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc option to produce PIC... -fPIC -DPIC
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc PIC flag -fPIC -DPIC works... yes
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc static flag -static works... yes
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc supports -c -o file.o... yes
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc supports -c -o file.o... (cached) yes
checking whether the /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc linker (/mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) supports shared libraries... yes
checking dynamic linker characteristics... Android linker
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking for x86_64-pc-linux-gnu-gcc... no
checking for gcc... gcc
checking for gcc... (cached) gcc
checking for suffix of native executables...
checking for a BSD-compatible install... /usr/bin/install -c
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for ANSI C header files... (cached) yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking size of int... 4
checking size of long... 4
checking whether cpp computation of bit length in ftconfig.in works... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... yes
checking for getpagesize... no
checking for working mmap... no
checking for memcpy... yes
checking for memmove... yes
checking gcc compiler flag -pedantic to assure ANSI C works correctly... ok, add it to XX_ANSIFLAGS
checking gcc compiler flag -ansi to assure ANSI C works correctly... ok, add it to XX_ANSIFLAGS
checking for ZLIB... yes
checking for LIBPNG... yes
checking for HARFBUZZ... yes
configure: creating ./config.status
config.status: creating unix-cc.mk
config.status: creating unix-def.mk
config.status: creating ftconfig.h
config.status: executing libtool commands
configure:

Library configuration:
external zlib: yes (pkg-config)
bzip2: no
libpng: yes (pkg-config)
harfbuzz: yes (pkg-config)

make: Nothing to be done for 'unix'.
make: Nothing to be done for 'all'.
rm -rf /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2
rm -f /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/ft2build.h
/usr/bin/mkdir -p /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/pkgconfig \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype/config \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/bin \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/share/aclocal \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/share/man/man1
./builds/unix/libtool --mode=install /usr/bin/install -c \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/libfreetype.la /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib
libtool: install: /usr/bin/install -c /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/.libs/libfreetype.lai /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/libfreetype.la
libtool: install: /usr/bin/install -c /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/.libs/libfreetype.a /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/libfreetype.a
libtool: install: chmod 644 /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/libfreetype.a
libtool: install: /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/libfreetype.a
for P in /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/tttables.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftoutln.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftstroke.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/t1tables.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/fterrors.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftcid.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftbitmap.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftmodapi.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftsystem.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftcffdrv.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftautoh.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftsynth.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftlcdfil.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftpfr.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftsizes.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftrender.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftlzw.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftfntfmt.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftglyph.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftlist.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftincrem.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftchapters.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftbdf.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftcache.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ttnameid.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftgzip.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftbzip2.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftmac.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/freetype.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftwinfnt.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/fttypes.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftotval.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftbbox.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftmm.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftadvanc.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftttdrv.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftmoderr.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftgasp.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftgxval.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftsnames.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/tttags.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ttunpat.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/fterrdef.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/fttrigon.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftimage.h ; do \
/usr/bin/install -c -m 644 \
$P /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype ; \
done
for P in /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftstdlib.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftconfig.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftmodule.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftoption.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftheader.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/ftmodule.h ; do \
/usr/bin/install -c -m 644 \
$P /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype/config ; \
done
/usr/bin/install -c -m 644 /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/ft2build.h \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/ft2build.h
/usr/bin/install -c -m 644 ./builds/unix/ftconfig.h \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype/config/ftconfig.h
/usr/bin/install -c -m 644 /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/ftmodule.h \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype/config/ftmodule.h
/usr/bin/install -c -m 755 ./builds/unix/freetype-config \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/bin/freetype-config
/usr/bin/install -c -m 644 ./builds/unix/freetype2.m4 \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/share/aclocal/freetype2.m4
/usr/bin/install -c -m 644 ./builds/unix/freetype2.pc \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/pkgconfig/freetype2.pc
/usr/bin/install -c -m 644 /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/docs/freetype-config.1 \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/share/man/man1/freetype-config.1
bindesh@linux-k2zc:/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3>

Thursday, March 10, 2016

How to compile libpng using Android NDK?

This page is for you if want to compile libpng for Android or just got a warning mail from Google PlayStore regading libpng vulnerability issue of old versions. "Google Play warning: You are using vulnerable version of libpng". This article/tutorial is about compiling libpng 1..6.19 for Android.


 

My setup:
  • OpenSuse Linux Leap 42.1.20151028 x86_64 (64Bit), AMD Athlon X2
  • Android NDK r10e-rc4 (64-bit). Directory name android-ndk-r10e-linux
  • Terminal / Bash shell. On Windows one needs to install binutils, development environment. Just install CodeBlocks windows or other such compiler. They contain most of needed tools.


Because my setup is Linux with disk limit due to 128GB SSD i have not installed 2 set of tools for each OS i.e. Linux and Windows. However it will not take more than minute to change the scripts to Windows. Most of my scripts are hard-coded for 64Bit Linux. Kindly change the variables to your NDK to let the scripts run bug free. Or for a person who just needs Android.mk file simply copy the content from end of this article.


Starting steps:
  • Download Android NDK and extract/install to a path without containing space or special characters. If using Linux then make symbolic link to home.
  • Download libpng version 1.6.19 (November 12, 2015)
  • Create a working directory where libpng will be compiled. Extract libpng.

Extracted libpng contains many files like README, TODO etc. One should read them as they contain important information. Before compiling libpng must be made aware of where compiler, other compiler related tools, headers and objects (compiled code) are saved. This information is collected by configure script. If interested open “configure” file in text editor and scroll to end. There are below lines -



# Assembler program.
AS=$lt_AS


# DLL creation program.
DLLTOOL=$lt_DLLTOOL

# Object dumper program.
OBJDUMP=$lt_OBJDUMP

# Whether or not to build shared libraries.
build_libtool_libs=$enable_shared

# The PATH separator for the build system.
PATH_SEPARATOR=$lt_PATH_SEPARATOR

# The host system.
host_alias=$host_alias
host=$host
host_os=$host_os



SED, GREP, FGREP, ECHO etc near end of file. These are the stuff configure script requires to build the final Makefile. We have to provide these things to configure script. After I started building libraries like libpng, FreeType, ImageMagick, GraphicsMagick etc for Android I collected some scripts from various sources like stackoverflow and build this script. It contains some hard-coded values but that takes minute to change as per system.


If project is small and contains few files we can build source without configure script or even Makefile. It is recommended that we understand the basics of this system. For example look at scripts directory there are many makefile.PLATFORM files where PLATFORM = msys, linux etc. We can use those makefiles to build a working Makefile or get information about build flags etc. But that's not easier than configure script.


Android Script

# AndroidBuild.sh START
#!/bin/sh
# remove flag for non neon ARM processors.

export HAS_NEON="--enable-arm-neon"
export CONFIGURATION_OPTIONS="--disable-shared $HAS_NEON"

# use custom build environment
# installation directory
export PREFIX=`pwd`/prefix

# Path of NDK. For simplicity make symlinks in home directories
export NDK=/mnt/work/SDK_IDE/android-ndk-r10e-linux/

#export NDK=/home/bindesh/bin/ndk (SYMLINK)
# processor specific libraries and includes.
# Suffix for arch-???. arch-arm arch-arm64 arch-mips arch-mips64 arch-x86 arch-x86_64
export ARCH=arm
 

# compiler for processor
export CROSS_COMPILE=arm-linux-androideabi

# Android platform version
export PLATFORM=android-8

# GCC compiler version
export GCC_VERSION=4.8

# Getting toolchain directory inside NDK from variables set above
# Hardcoded for linux running on x86 cpu 64-Bit
export ANDROID_PREFIX=${NDK}/toolchains/$CROSS_COMPILE-$GCC_VERSION/prebuilt/linux-x86_64

# SYSROOT. usr dir i.e. usr/include, usr/lib
export SYSROOT=${NDK}/platforms/$PLATFORM/arch-$ARCH
export CROSS_PATH=${ANDROID_PREFIX}/bin/${CROSS_COMPILE}

# Some compiler and binutils. More might be needed depending on source.
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib

# package configuration file save location
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig

# Flags for compiler
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include"

export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"

./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} "$@" $CONFIGURATION_OPTIONS

make
make install
 

# AndroidBuild.sh END



Copy all lines above and paste in a new file AndroidBuild.sh and save. Then change the variables valid for your system. Create folder prefix or whatever name you like. Change NDK=/mnt/work/SDK_IDE/android-ndk-r10e-linux/ and compiler related values as per your system. This script copied from web can cause error due to removal of newlines for strange reasons. Ensure # is ahead of comments.

Now run sh AndroidBuild.sh. It should end without errors. This will install all built files in prefix directory. Now we can copy libpng16.a renamed to libpng.a and headers directory.

Links: Script file http://txt.do/5vb70 Or http://textuploader.com/5vb70


Above script is common to most of tasks and is best for building most of C libraries. To add C++support more variables are needed. Some possible errors:

  • Error in running compiler tools. This can be due to incorrect final paths of build tools. Look at config.log and cross check if resulting paths are correct.
  • Error in finding libraries. This can be because of wrong names of libraries and -l parameter to compiler. Ensure path and names are correct. Configure script runs a lot of tests which tests each used libraries with a small sample code. Check the results of these sample codes in config.log.

If everything seems not working then ensure the installation of tools is correct and they do their job. Make simple programs and test them. Test NDK with Android Studio or Eclipse. Do these types of tests. I myself have spent time frustrated with these types of problems. In Linux i even suffered problems like executable flag of executable files were removed due to unknown reason!.



Android.mk


LOCAL_PATH := $(call my-dir)

# $(call my-dir) return path of this Android.mk directory

PNG_SRC_PATH    :=
INC_PNG                := $(LOCAL_PATH)/


include $(CLEAR_VARS)

LOCAL_MODULE    := libpng
LOCAL_CFLAGS    :=
LOCAL_CPPFLAGS  := ${LOCAL_CFLAGS}

LOCAL_C_INCLUDES  :=  \
    ${INC_PNG} \
       
LOCAL_SRC_FILES := \
    ${PNG_SRC_PATH}pngerror.c \
    ${PNG_SRC_PATH}pngwio.c \
    ${PNG_SRC_PATH}pngwrite.c \
    ${PNG_SRC_PATH}pngwutil.c \
    ${PNG_SRC_PATH}pngwtran.c \
    ${PNG_SRC_PATH}pngset.c \
    ${PNG_SRC_PATH}pngtrans.c \
    ${PNG_SRC_PATH}example.c \
    ${PNG_SRC_PATH}png.c \
    ${PNG_SRC_PATH}pngrtran.c \
    ${PNG_SRC_PATH}pngmem.c \
    ${PNG_SRC_PATH}pngpread.c \
    ${PNG_SRC_PATH}pngrutil.c \
    ${PNG_SRC_PATH}pngrio.c \
    ${PNG_SRC_PATH}pngget.c \
    ${PNG_SRC_PATH}pngread.c
   
   
   

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)

  LOCAL_SRC_FILES += ${PNG_SRC_PATH}arm/arm_init.c
  LOCAL_SRC_FILES += ${PNG_SRC_PATH}arm/filter_neon.S
  LOCAL_SRC_FILES += ${PNG_SRC_PATH}arm/filter_neon_intrinsics.c
endif


LOCAL_LDLIBS    := -llog -L../lib
# -lz -lm

include $(BUILD_STATIC_LIBRARY)