If you ever tried to create an OCR app for Android you must have stumbled upon the OCR library by Google Tesseract. And then the problems began.
To use the library in your project you first need to build it. But building the library to be compatible with gradle, which is the new build system for Android projects is little not so easily stated anywhere in the library manual.
When I tried to build the library, it took me freaking 9 hours to figure all the how tos?
So, here I am helping you to save your precious hours. (Don’t waste these watching late night infomercials for god’s sake! ).
Here we go.
Step 1 :
The first step. Download the NDK. That is used to build the library.
Download it from here. It is around 300+ MB so keep your net plan nourished.
Step 2 :
Better way to go is to use a fork of Tesseract, Tess-Two. Tess-Two can be found on GitHub.
Execute following commands to build the library Tess-Two using NDK.
git clone git://github.com/rmtheis/tess-two tess
cd tess
cd tess-two
ndk-build
android update project --path .
ant release
We can live without building eyes-two for this time.
Building will take few minutes. After you have successfully built tess-two, give yourself a little treat. You are almost done.
Step 3 :
Now you are ready to use the library in your Android project.
Copy the tess-two folder (tess/tess-two), in the main folder of the application project.
Suppose name of your application is “MyApp” copy the folder at “MyApp/”.
Step 4 :
Now its time to play the trick. The library was build using ANT. But Android projects use Gradle these days. Interesting…
We need to add a “build.gradle” file at location “tess-two/”.
The build file can be found here.
Then include following line in project.settings file.
include ':tess-two'
Step 5 :
Build the project and you are just one step away from being done.
Step 6 :
The most important step. After completing steps 1-5, throw your hands up in the air! 😀 😀 You are now done!
Ready to harness the power of OCR.
20 responses to “How to build Tesseract OCR library for Android Studio?”
Hi I’v got some errors following the tutorial , can u help me plyz ?
LikeLike
Sure. Email your issues to me.
LikeLike
I am having an issue will building the library…. I am getting errors at “ant release” in compile and build is getting failed
LikeLike
Wow, this one the latest tutorial that I found .
May I know, which OS, NDK that you use ..
I had stuck one week on the ndk-build ..
make.exe *** Waiting for unfinished job.
I am very newbie .. But this project is very important .. 😥 .
Thank you in advance ..
LikeLike
I am getting this error. Please help me
@Below Line
baseApi.init(“/mnt/sdcard/tesseract/tessdata/eng.trainedata”, “eng”);
Error : Caused by: java.lang.IllegalArgumentException: Data path does not exist!
LikeLike
i got this error: Error: The project either has no target set or the target is invalid.
when i’m trying to do: android update project –path .
LikeLike
I think you should add –target option .
You can get your all targetId with command : android list targets
Then android update project –path . –target 1 for example
They are API versions
LikeLike
I am not able to copy the files from tess-two into android studio. It isays : Can’t copy class files and gives an error. Please help !
LikeLike
salam. i need a bit help actually, i got stuck on ur step 2 tutorial, i do really apreciate if u want to help me this tutorial just so important for my final project, i dont even know how to execute following commands to build the library Tess-Two using NDK, please help me get out of step 2, ur help means a lot. if u want to help me please contact this email : aghnia35@gmail.com . thankyou. salam.
LikeLike
My friend;
I have tried to follow all steps you have; however, I could not performed two steps below. I have searched my computer for “android.exe and ant.exe”; however, I have no luck. I have tried google for android.exe, but nothing there. I also update sdk platform tools and download apache ant, but nothing seem to work.
Thanks
android update project –path .
ant release
LikeLike
I have downloaded the android NDK to my UBuntu 14.04 LTS. What am I supposed to do after downloading NDK ?
LikeLike
[…] Source : https://priyankvex.wordpress.com/2015/08/30/how-to-build-tesseract-ocr-library-for-android-studio/ […]
LikeLike
So the app doesn’t need internet connection to use? Can’t I make an online app using tesseract? I’m really confuse here, please help 😦
LikeLike
To doesn’t need internet as everything is happening on device.
You can make online app but then you’ll have to send image to your server which analyses the image.
LikeLike
Hello priyank! I have followed all 6 steps successfully. I run project also. But I am not getting how to use ocr library. Please help. It’s running activity in my project. Nothing in ocr is happening. Guide please.
LikeLike
Hello priyank! I have followed all 6 steps successfully. I ran project also. But I am not getting how to use ocr library. Please help. It’s running activity in my project. Nothing in ocr is happening. Guide please.
LikeLike
Hello Priyank. I’m not able to execute the ant release command. I’ve set my path variables. It gives an error package android.support.annotation does not exist. What do I do?
LikeLike
OMG , Amazing !! Everything Informative This Is really Ah Very good post. Taking the time and actual effort to produce a superb article… Thanks For Sharing
LikeLike
Hmm it looks like your website ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I too am an aspiring blog blogger but I’m still new to everything. Do you have any tips for novice blog writers? I’d genuinely appreciate it.|
LikeLike
Pretty! This has been an extremely wonderful article. Thank you for providing these details.|
LikeLike