Professional Documents
Culture Documents
About tesseract
Tesseract in android
If you are using tesseract library in android application, there is a previously built
android application project exists(A fork of tesseract tools for android).
You have to build this tess-two project with android-ndk and then add the build
project as library project to you android project. But this tess-two library not
supports for build with gradle android projects. So we have to create gradle
project with tess-two(configure tesst-two with gradle)
There are few steps you need to follow when integrating tesst-two with gradle
android project.
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 1/11
28/1/2018 Tesseract with andoird and gradle (Example)
Now copy the entire tess-two directory into the libraries folder you just
created.
Delete the libs folder in the tess-two directory. If you like, delete the
project.properties, build.xml, .classpath, and .project. files as well. You
don't need them.
Create a build.gradle file in the tess-two directory, (I have created a
build.gradle file, you can just reuse it). Following is my build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
jniLibs.srcDirs = ['libs']
}
}
https://github.com/erangaeb/dev-notes/blob/master/tesseract/build.gradle
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 2/11
28/1/2018 Tesseract with andoird and gradle (Example)
include ':libraries:tess-two'
Then sync the project in Android Studio and add the new tess-two library
as module dependency to you main project(after sync tess-two library
should appear as a module, you can add it to your project from project
settings in android studio)
Recommend
Say Thanks
Respond
34 Responses
harbachek
How do we use it then, can you give an example?
itseranga
Hi,
harbachek
Thank you I found it already and I think it is really good.
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 3/11
28/1/2018 Tesseract with andoird and gradle (Example)
harbachek
What should there be if it says that a newer version of gradle should be used here
com.android.tools.build:gradle:0.9.+ (at least 12.0) change it to 12.0+?
itseranga
What is the gradle version you have installed?
harbachek
The newest that comes with AS 0.8.
kiddbubu
i did everything as you described, how can i import the library into an activity?
itseranga
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.setDebug(true);
baseApi.init(DATA_PATH, LANG);
baseApi.setImage(bitmap);
String recognizedText = baseApi.getUTF8Text();
baseApi.end();
tonymalghem
Hi!
I did everything that you said, but unfortunately, my app keeps crashing and I have this
error in logcat : Couldn't load lept from loader dalvik.system.PathClassLoader[...]:
findLibrary returned null
itseranga
Did you build the tesseract library with android-ndk ??
Seems like "liblept.so" (shared library) file can not found on specific library path
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 4/11
28/1/2018 Tesseract with andoird and gradle (Example)
blizzshot
Hi eranga,
Nice guide as i am able to blend tesseract with my android studio project, just one issue
when i try to make module it kept on saying "Error:(14, 40) error: package
com.googlecode.tesseract.android does not exist" even though i've set it as a dependency
and import it to my code
sagarwal10
Thank you for posting this. Very useful!
bravevu
Thank you. Follow all steps, it is correct.
If someone has project including tess-two in Eclipse, now convert to Android Studio, should
remove directory tess-two from generating. In build.gradle, remove:
compile project(':tesstwo')
italomaia
I followed the steps and got this error:
java.lang.UnsatisfiedLinkError: Couldn't load lept from loader
dalvik.system.PathClassLoader[dexPath=/data/app/br.com.notasocial.cupom-
38.apk,libraryPath=/data/app-lib/br.com.notasocial.cupom-38]: findLibrary returned null
shashankdass
I followed all the steps. I am still getting the following error on running my app.
matts
Hi.... Even i got the same error - java.lang.UnsatisfiedLinkError: Couldn't load lept from
loader.
Is there any particular reason why we should delete the libs folder from the tess-two
library?
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 5/11
28/1/2018 Tesseract with andoird and gradle (Example)
matts
Issue Resolved :) .libs folder shouldn't be removed
rijulg
After spending a whole day on trying to compile, build and redoing it all many times, Finally
a solution that works. Thanks a lot Mr. bandara
p-rothen
I dont' find "project settings" in android studio, pls help. I'am stuck at the last step. Did you
compile tess-two with 32/64bits ndk? Thanks D:
xxkfjfredxx
Hi this example is best
http://www.codeproject.com/Tips/840623/Android-Character-Recognition
aakarshika
https://code.google.com/p/android/issues/detail?id=74132 does anyone have a solution to
this problem?
p-rothen
I solved my problem above, Ctrl+alt+shift+s ->Dependencies
AnCh
Use ndk-build to build the tess-two library. If you have already built it before copying to
libraries, then don't delete the libs folder. Rest everything worked like charm. Thanks a lot.
jyjy123
Hi, after adding it as a module dependency, it shows "Error: Configuration with name
'default' not found". May i know whats wrong? Everything was working fine before that.
Thank you!
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 6/11
28/1/2018 Tesseract with andoird and gradle (Example)
wasif_514
After adding library to settings.gradle file. I got following error:
sourceSets.main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
jniLibs.srcDirs = ['libs']
}
By this change, I got list of errors and build failed. Here are few errors:
sandeepgurram
thanks dude.. you made my day. But only correction to be made is we should not remove
libs folder and target version in gradle file of our app and tess-two should be same.
ekilla
The libs folder is REQUIRED for the app to work. If the libs folder is missing from the
commit of tess-two obtained from github, Use ndk to build the tess-two project. But
everything else works okay. Thanks.
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 7/11
28/1/2018 Tesseract with andoird and gradle (Example)
meta0102
hi, should i really add the whole tess-two directory to my project? after android-ndk the
directory is about 400mb! thanks
Tazonis
Hi, am new to this and I would like to play with tess on android. So far I managed to build
the tess two library with NDK10 but am stuck with android update project --path and ant
release (android not a valid command). Ant has something to do with Apache so I guess I
have to install ant, but what's update project command and what the path var means? Am
already on a terminal inside tess two folder and after building with SDK I noticed the files
changed close to an android build with a manifest and build xml file. Am using android
studio so do I just have to copy tess two file to MyLib folder or do I have to go trough
android update project --path and ant release first before I copy the folder to my MyLib
folder?
Regards
a fellow senior programmer.
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 8/11
28/1/2018 Tesseract with andoird and gradle (Example)
yvtheja
Use this if you are using latest Android Studio.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
}
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
jniLibs.srcDirs = ['libs']
}
It worked for me :)
AnithaGK
I am following the steps mentioned above
In Configure tess-two with gradle tells to copy and paste the tess-two folder to my Project
but when I paste, I get an error stating Cannot create class-file and none of my `.java' files
get copied.
Where am I going wrong?
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 9/11
28/1/2018 Tesseract with andoird and gradle (Example)
shivanraptor
This article is outdated. tess-two can now be used directly with gradle: compile
'com.rmtheis:tess-two:5.4.1'. See this
hupernikao07
Error:(4, 0) Plugin with id 'com.github.dcendents.android-maven' not found.
rakeshvasal
Hey,I have tried this and the project is workin...thanks for that but the output is bit weird.....
Like if the text contains 10 words only one word is correct rest all are just symbols or
random letters..
Do we have to copy the eyes-two directory also or is it the whole tess-two master that we
have to copy...
Filed Under
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 10/11
28/1/2018 Tesseract with andoird and gradle (Example)
https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 11/11