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 TessBaseApi();
It throws the following error
Error Code: 2
Output:
In file included from tesstwo/src/main/jni/com_googlecode_leptonica_android/box.cpp:17:0:
tesstwo/src/main/jni/com_googlecode_leptonica_android/common.h:22:24: fatal error: allheaders.h: No such file or directory
#include <allheaders.h>
^
compilation terminated.
make: ***
I have looked into /jni/com_googlecode_leptonica_android/src/src
and find the allheaders.h
file there. I have a feeling my paths are wrong, but I've tried almost everything and no avail. What's the issue?
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
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.+'
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'] } }
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 !!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.