title: How should I compile tesseract-4 for Android platform?
body: <p>I created a project named <code>NDKTest3</code>, then created a folder named <code>jni</code> inside the root of the project and put these 3 files inside it:</p>
  
  <p>Android.mk:</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  LOCAL_MODULE := ndktest3
  LOCAL_SRC_FILES := test.c
  include $(BUILD_SHARED_LIBRARY)
  include $(LOCAL_PATH)/../tesseract/android/jni/Android.mk
  </code></pre>
  
  <p>Application.mk:</p>
  
  <pre><code>APP_ABI := all
  </code></pre>
  
  <p>test.c:</p>
  
  <pre><code>(blank)
  </code></pre>
  
  <p>I also edited my `build.gradle(app) as below:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 26
      defaultConfig {
          applicationId "com.m.ndktest3"
          minSdkVersion 21
          targetSdkVersion 26
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  
          ndk{
              moduleName "ndktest3"
          }
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  
      externalNativeBuild{
          ndkBuild{
              path '../jni/Android.mk'
          }
      }
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'com.android.support:appcompat-v7:26.1.0'
      implementation 'com.android.support.constraint:constraint-layout:1.0.2'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'com.android.support.test:runner:1.0.1'
      androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
  }
  </code></pre>
  
  <p>settings.gradle:</p>
  
  <pre><code>include ':app'
  include ':tesseract'
  </code></pre>
  
  <p>Then I copied the <code>tesseract</code> folder inside the root of my project. You can see my project below:</p>
  
  <p><a href="https://i.stack.imgur.com/dGoLf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dGoLf.png" alt="enter image description here"></a></p>
  
  <p>But when I want to sync the project it gives me this error message:</p>
  
  <pre><code>External Native Build Issues
  Build command failed.
  Error while executing process /home/m/Android/Sdk/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/m/AndroidStudioProjects/NDKTest3/jni/Android.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/home/m/AndroidStudioProjects/NDKTest3/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/home/m/AndroidStudioProjects/NDKTest3/app/build/intermediates/ndkBuild/debug/lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
  local c includes= /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../api /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccmain /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccstruct /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccutil /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../classify /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../cutil /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../dict /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../image /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../textord /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../third_party /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../wordrec /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../opencl /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../viewer /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../../leptonica/include
  local path=/home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni
  local src files  = ../../api/baseapi.cpp ../../api/capi.cpp ../../api/renderer.cpp ../../ccmain/adaptions.cpp ../../ccmain/applybox.cpp ../../ccmain/control.cpp ../../ccmain/docqual.cpp ../../ccmain/equationdetect.cpp ../../ccmain/fixspace.cpp ../../ccmain/fixxht.cpp ../../ccmain/linerec.cpp ../../ccmain/ltrresultiterator.cpp ../../ccmain/osdetect.cpp ../../ccmain/output.cpp ../../ccmain/pageiterator.cpp ../../ccmain/pagesegmain.cpp ../../ccmain/pagewalk.cpp ../../ccmain/paragraphs.cpp ../../ccmain/paramsd.cpp ../../ccmain/par_control.cpp ../../ccmain/pgedit.cpp ../../ccmain/recogtraining.cpp ../../ccmain/reject.cpp ../../ccmain/resultiterator.cpp ../../ccmain/superscript.cpp ../../ccmain/tessbox.cpp ../../ccmain/tessedit.cpp ../../ccmain/tesseractclass.cpp ../../ccmain/tessvars.cpp ../../ccmain/tfacepp.cpp ../../ccmain/thresholder.cpp ../../ccmain/werdit.cpp ../../ccstruct/blamer.cpp ../../ccstruct/blobbox.cpp ../../ccstruct/blobs.cpp ../../ccstruct/blread.cpp ../../ccstruct/boxread.cpp ../../ccstruct/boxword./home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/Android.mk:48: *cp** Android NDK:p  Aborting.   .. .  Stop.
  /../ccstruct/ccstruct.cpp ../../ccstruct/coutln.cpp ../../ccstruct/detlinefit.cpp ../../ccstruct/dppoint.cpp ../../ccstruct/fontinfo.cpp ../../ccstruct/genblob.cpp ../../ccstruct/imagedata.cpp ../../ccstruct/linlsq.cpp ../../ccstruct/matrix.cpp ../../ccstruct/mod128.cpp ../../ccstruct/normalis.cpp ../../ccstruct/ocrblock.cpp ../../ccstruct/ocrpara.cpp ../../ccstruct/ocrrow.cpp ../../ccstruct/otsuthr.cpp ../../ccstruct/pageres.cpp ../../ccstruct/params_training_featdef.cpp ../../ccstruct/pdblock.cpp ../../ccstruct/points.cpp ../../ccstruct/polyaprx.cpp ../../ccstruct/polyblk.cpp ../../ccstruct/publictypes.cpp ../../ccstruct/quadlsq.cpp ../../ccstruct/quspline.cpp ../../ccstruct/ratngs.cpp ../../ccstruct/rect.cpp ../../ccstruct/rejctmap.cpp ../../ccstruct/seam.cpp ../../ccstruct/split.cpp ../../ccstruct/statistc.cpp ../../ccstruct/stepblob.cpp ../../ccstruct/vecfuncs.cpp ../../ccstruct/werd.cpp ../../ccutil/ambigs.cpp ../../ccutil/basedir.cpp ../../ccutil/bits16.cpp ../../ccutil/bitvector.cpp ../../ccutil/ccutil.cpp ../../ccutil/clst.cpp ../../ccutil/elst2.cpp ../../ccutil/elst.cpp ../../ccutil/errcode.cpp ../../ccutil/globaloc.cpp ../../ccutil/indexmapbidi.cpp ../../ccutil/mainblk.cpp ../../ccutil/memry.cpp ../../ccutil/params.cpp ../../ccutil/scanutils.cpp ../../ccutil/serialis.cpp ../../ccutil/strngs.cpp ../../ccutil/tessdatamanager.cpp ../../ccutil/tprintf.cpp ../../ccutil/unicharcompress.cpp ../../ccutil/unichar.cpp ../../ccutil/unicharmap.cpp ../../ccutil/unicharset.cpp ../../ccutil/unicodes.cpp ../../ccutil/universalambigs.cpp ../../classify/adaptive.cpp ../../classify/adaptmatch.cpp ../../classify/blobclass.cpp ../../classify/classify.cpp ../../classify/cluster.cpp ../../classify/clusttool.cpp ../../classify/cutoffs.cpp ../../classify/errorcounter.cpp ../../classify/featdefs.cpp ../../classify/float2int.cpp ../../classify/fpoint.cpp ../../classify/intfeaturedist.cpp ../../classify/intfeaturemap.cpp ../../classify/intfeaturespace.cpp ../../classify/intfx.cpp ../../classify/intmatcher.cpp ../../classify/intproto.cpp ../../classify/kdtree.cpp ../../classify/mastertrainer.cpp ../../classify/mf.cpp ../../classify/mfdefs.cpp ../../classify/mfoutline.cpp ../../classify/mfx.cpp ../../classify/normfeat.cpp ../../classify/normmatch.cpp ../../classify/ocrfeatures.cpp ../../classify/outfeat.cpp ../../classify/picofeat.cpp ../../classify/protos.cpp ../../classify/sampleiterator.cpp ../../classify/shapeclassifier.cpp ../../classify/shapetable.cpp ../../classify/tessclassifier.cpp ../../classify/trainingsample.cpp ../../classify/trainingsampleset.cpp ../../cutil/bitvec.cpp ../../cutil/callcpp.cpp ../../cutil/cutil_class.cpp ../../cutil/cutil.cpp ../../cutil/danerror.cpp ../../cutil/efio.cpp ../../cutil/emalloc.cpp ../../cutil/oldlist.cpp ../../cutil/structures.cpp ../../dict/context.cpp ../../dict/dawg_cache.cpp ../../dict/dawg.cpp ../../dict/dict.cpp ../../dict/hyphen.cpp ../../dict/permdawg.cpp ../../dict/stopper.cpp ../../dict/trie.cpp ../../textord/alignedblob.cpp ../../textord/baselinedetect.cpp ../../textord/bbgrid.cpp ../../textord/blkocc.cpp ../../textord/blobgrid.cpp ../../textord/ccnontextdetect.cpp ../../textord/cjkpitch.cpp ../../textord/colfind.cpp ../../textord/colpartition.cpp ../../textord/colpartitiongrid.cpp ../../textord/colpartitionset.cpp ../../textord/devanagari_processing.cpp ../../textord/drawedg.cpp ../../textord/drawtord.cpp ../../textord/edgblob.cpp ../../textord/edgloop.cpp ../../textord/equationdetectbase.cpp ../../textord/fpchop.cpp ../../textord/gap_map.cpp ../../textord/imagefind.cpp ../../textord/linefind.cpp ../../textord/makerow.cpp ../../textord/oldbasel.cpp ../../textord/pithsync.cpp ../../textord/pitsync1.cpp ../../textord/scanedg.cpp ../../textord/sortflts.cpp ../../textord/strokewidth.cpp ../../textord/tabfind.cpp ../../textord/tablefind.cpp ../../textord/tablerecog.cpp ../../textord/tabvector.cpp ../../textord/textlineprojection.cpp ../../textord/textord.cpp ../../textord/topitch.cpp ../../textord/tordmain.cpp ../../textord/tospace.cpp ../../textord/tovars.cpp ../../textord/underlin.cpp ../../textord/wordseg.cpp ../../textord/workingpartset.cpp ../../viewer/scrollview.cpp ../../viewer/svmnode.cpp ../../viewer/svpaint.cpp ../../viewer/svutil.cpp ../../wordrec/associate.cpp ../../wordrec/chop.cpp ../../wordrec/chopper.cpp ../../wordrec/drawfx.cpp ../../wordrec/findseam.cpp ../../wordrec/gradechop.cpp ../../wordrec/language_model.cpp ../../wordrec/lm_consistency.cpp ../../wordrec/lm_pain_points.cpp ../../wordrec/lm_state.cpp ../../wordrec/outlines.cpp ../../wordrec/params_model.cpp ../../wordrec/pieces.cpp ../../wordrec/plotedges.cpp ../../wordrec/render.cpp ../../wordrec/segsearch.cpp ../../wordrec/tface.cpp ../../wordrec/wordclass.cpp ../../wordrec/wordrec.cpp
  Android NDK: /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/Android.mk: Cannot find module with tag 'base/port' in import path    
  Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?    
  Android NDK: The following directories were searched:    
  Android NDK:         
  Build command failed.
  Error while executing process /home/m/Android/Sdk/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/m/AndroidStudioProjects/NDKTest3/jni/Android.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0 APP_PLATFORM=android-21 NDK_OUT=/home/m/AndroidStudioProjects/NDKTest3/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=/home/m/AndroidStudioProjects/NDKTest3/app/build/intermediates/ndkBuild/release/lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
  local c includes= /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../api /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccmain /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccstruct /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccutil /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../classify /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../cutil /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../dict /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../image /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../textord /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../third_party /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../wordrec /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../opencl /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../viewer /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../../leptonica/include
  local path=/home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni
  local src files  = ../../api/baseapi.cpp ../../api/capi.cpp ../../api/renderer.cpp ../../ccmain/adaptions.cpp ../../ccmain/applybox.cpp ../../ccmain/control.cpp ../../ccmain/docqual.cpp ../../ccmain/equationdetect.cpp ../../ccmain/fixspace.cpp ../../ccmain/fixxht.cpp ../../ccmain/linerec.cpp ../../ccmain/ltrresultiterator.cpp ../../ccmain/osdetect.cpp ../../ccmain/output.cpp ../../ccmain/pageiterator.cpp ../../ccmain/pagesegmain.cpp ../../ccmain/pagewalk.cpp ../../ccmain/paragraphs.cpp ../../ccmain/paramsd.cpp ../../ccmain/par_control.cpp ../../ccmain/pgedit.cpp ../../ccmain/recogtraining.cpp ../../ccmain/reject.cpp ../../ccmain/resultiterator.cpp ../../ccmain/superscript.cpp ../../ccmain/tessbox.cpp ../../ccmain/tessedit.cpp ../../ccmain/tesseractclass.cpp ../../ccmain/tessvars.cpp ../../ccmain/tfacepp.cpp ../../ccmain/thresholder.cpp ../../ccmain/werdit.cpp ../../ccstruct/blamer.cpp ../../ccstruc/home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/Android.mk:48: *** Android NDK: Aborting.    .  Stop.
  t/blobbox.cpp ../../ccstruct/blobs.cpp ../../ccstruct/blread.cpp ../../ccstruct/boxread.cpp ../../ccstruct/boxword.cpp ../../ccstruct/ccstruct.cpp ../../ccstruct/coutln.cpp ../../ccstruct/detlinefit.cpp ../../ccstruct/dppoint.cpp ../../ccstruct/fontinfo.cpp ../../ccstruct/genblob.cpp ../../ccstruct/imagedata.cpp ../../ccstruct/linlsq.cpp ../../ccstruct/matrix.cpp ../../ccstruct/mod128.cpp ../../ccstruct/normalis.cpp ../../ccstruct/ocrblock.cpp ../../ccstruct/ocrpara.cpp ../../ccstruct/ocrrow.cpp ../../ccstruct/otsuthr.cpp ../../ccstruct/pageres.cpp ../../ccstruct/params_training_featdef.cpp ../../ccstruct/pdblock.cpp ../../ccstruct/points.cpp ../../ccstruct/polyaprx.cpp ../../ccstruct/polyblk.cpp ../../ccstruct/publictypes.cpp ../../ccstruct/quadlsq.cpp ../../ccstruct/quspline.cpp ../../ccstruct/ratngs.cpp ../../ccstruct/rect.cpp ../../ccstruct/rejctmap.cpp ../../ccstruct/seam.cpp ../../ccstruct/split.cpp ../../ccstruct/statistc.cpp ../../ccstruct/stepblob.cpp ../../ccstruct/vecfuncs.cpp ../../ccstruct/werd.cpp ../../ccutil/ambigs.cpp ../../ccutil/basedir.cpp ../../ccutil/bits16.cpp ../../ccutil/bitvector.cpp ../../ccutil/ccutil.cpp ../../ccutil/clst.cpp ../../ccutil/elst2.cpp ../../ccutil/elst.cpp ../../ccutil/errcode.cpp ../../ccutil/globaloc.cpp ../../ccutil/indexmapbidi.cpp ../../ccutil/mainblk.cpp ../../ccutil/memry.cpp ../../ccutil/params.cpp ../../ccutil/scanutils.cpp ../../ccutil/serialis.cpp ../../ccutil/strngs.cpp ../../ccutil/tessdatamanager.cpp ../../ccutil/tprintf.cpp ../../ccutil/unicharcompress.cpp ../../ccutil/unichar.cpp ../../ccutil/unicharmap.cpp ../../ccutil/unicharset.cpp ../../ccutil/unicodes.cpp ../../ccutil/universalambigs.cpp ../../classify/adaptive.cpp ../../classify/adaptmatch.cpp ../../classify/blobclass.cpp ../../classify/classify.cpp ../../classify/cluster.cpp ../../classify/clusttool.cpp ../../classify/cutoffs.cpp ../../classify/errorcounter.cpp ../../classify/featdefs.cpp ../../classify/float2int.cpp ../../classify/fpoint.cpp ../../classify/intfeaturedist.cpp ../../classify/intfeaturemap.cpp ../../classify/intfeaturespace.cpp ../../classify/intfx.cpp ../../classify/intmatcher.cpp ../../classify/intproto.cpp ../../classify/kdtree.cpp ../../classify/mastertrainer.cpp ../../classify/mf.cpp ../../classify/mfdefs.cpp ../../classify/mfoutline.cpp ../../classify/mfx.cpp ../../classify/normfeat.cpp ../../classify/normmatch.cpp ../../classify/ocrfeatures.cpp ../../classify/outfeat.cpp ../../classify/picofeat.cpp ../../classify/protos.cpp ../../classify/sampleiterator.cpp ../../classify/shapeclassifier.cpp ../../classify/shapetable.cpp ../../classify/tessclassifier.cpp ../../classify/trainingsample.cpp ../../classify/trainingsampleset.cpp ../../cutil/bitvec.cpp ../../cutil/callcpp.cpp ../../cutil/cutil_class.cpp ../../cutil/cutil.cpp ../../cutil/danerror.cpp ../../cutil/efio.cpp ../../cutil/emalloc.cpp ../../cutil/oldlist.cpp ../../cutil/structures.cpp ../../dict/context.cpp ../../dict/dawg_cache.cpp ../../dict/dawg.cpp ../../dict/dict.cpp ../../dict/hyphen.cpp ../../dict/permdawg.cpp ../../dict/stopper.cpp ../../dict/trie.cpp ../../textord/alignedblob.cpp ../../textord/baselinedetect.cpp ../../textord/bbgrid.cpp ../../textord/blkocc.cpp ../../textord/blobgrid.cpp ../../textord/ccnontextdetect.cpp ../../textord/cjkpitch.cpp ../../textord/colfind.cpp ../../textord/colpartition.cpp ../../textord/colpartitiongrid.cpp ../../textord/colpartitionset.cpp ../../textord/devanagari_processing.cpp ../../textord/drawedg.cpp ../../textord/drawtord.cpp ../../textord/edgblob.cpp ../../textord/edgloop.cpp ../../textord/equationdetectbase.cpp ../../textord/fpchop.cpp ../../textord/gap_map.cpp ../../textord/imagefind.cpp ../../textord/linefind.cpp ../../textord/makerow.cpp ../../textord/oldbasel.cpp ../../textord/pithsync.cpp ../../textord/pitsync1.cpp ../../textord/scanedg.cpp ../../textord/sortflts.cpp ../../textord/strokewidth.cpp ../../textord/tabfind.cpp ../../textord/tablefind.cpp ../../textord/tablerecog.cpp ../../textord/tabvector.cpp ../../textord/textlineprojection.cpp ../../textord/textord.cpp ../../textord/topitch.cpp ../../textord/tordmain.cpp ../../textord/tospace.cpp ../../textord/tovars.cpp ../../textord/underlin.cpp ../../textord/wordseg.cpp ../../textord/workingpartset.cpp ../../viewer/scrollview.cpp ../../viewer/svmnode.cpp ../../viewer/svpaint.cpp ../../viewer/svutil.cpp ../../wordrec/associate.cpp ../../wordrec/chop.cpp ../../wordrec/chopper.cpp ../../wordrec/drawfx.cpp ../../wordrec/findseam.cpp ../../wordrec/gradechop.cpp ../../wordrec/language_model.cpp ../../wordrec/lm_consistency.cpp ../../wordrec/lm_pain_points.cpp ../../wordrec/lm_state.cpp ../../wordrec/outlines.cpp ../../wordrec/params_model.cpp ../../wordrec/pieces.cpp ../../wordrec/plotedges.cpp ../../wordrec/render.cpp ../../wordrec/segsearch.cpp ../../wordrec/tface.cpp ../../wordrec/wordclass.cpp ../../wordrec/wordrec.cpp
  Android NDK: /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/Android.mk: Cannot find module with tag 'base/port' in import path    
  Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?    
  Android NDK: The following directories were searched:    
  Android NDK:         
  </code></pre>