I am following the tutorial from this tesseract tutorial and had everything go smoothly up until my actual running of the Java code. When I try
new TessBaseA
Ppl, After struggling a day.. finally got the solution
In build.gradle of tess-two module add the below code:
sourceSets.main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
jni.srcDirs = []
jniLibs.srcDirs = ['src/main/jniLibs']
}
Main thing is please check manually weather all those file paths specified in above code exists in tess-two module!!
Check in which path "liblept.so" and other ".so" files exist in tess-two library. For me it was inside /tesstwo/src/main/jniLibs/armeabi-v7a . Hence i have made jniLibs.srcDirs = ['src/main/jniLibs'] in above code. Hope it helps !!
I also ran into this problem with Android Studio. After googling some more i found this issue. https://code.google.com/p/android/issues/detail?id=74132
Apparently the NDK plugin generates it's own Android.mk file and ignore any existing one, so the recommended way is to run ndk-build to generate the native .so files.
When I used ndk-build in the tess-two directory it compiles just fine and the .so files is created.
How you can include native libraries in gradle and android studio is described in this post: Add pre-built .so files in project using Android Gradle plugin 0.7.3
At some point Android Studio suggests to set
jni.srcDirs = []
leading to following sourceSets in the gradle.build of my tess-two library project
sourceSets.main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
jni.srcDirs = []
jniLibs.srcDirs = ['src/main/libs']
}
With correct src path entered here this actualy works
I'm not sure if it works for you but in my case, here's what I've done:
1. In common.h: change#include <allheaders.h>
into #include <src/src/allheaders.h>
.
2. In the library project build.gradle: add this
sourceSets{
main {
manifest.srcFile 'AndroidManifest.xml'
jni.srcDirs = []
jniLibs.srcDirs = ['src/main/jniLibs']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
This works for me: https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle
But do not delete libs directory!
Set compileSdkVersion
, buildToolsVersion
, minSdkVersion
and targetSdkVersio
to the same values as in project buil.gradle
I also change classpath 'com.android.tools.build:gradle:0.9.+'
to classpath 'com.android.tools.build:gradle:1.0.+'