Missing allheaders.h in Android Studio Project
I am following the tutorial from this tesseract tutorial and everything went smoothly before actually running 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 looked /jni/com_googlecode_leptonica_android/src/src
and found the file there allheaders.h
. I have a feeling that my paths are wrong, but I've tried almost everything to no avail. What's the problem?
source to share
I also faced this issue with Android Studio. After I came to search I found this problem. https://code.google.com/p/android/issues/detail?id=74132
Apparently the NDK plugin generates its own Android.mk file and ignores any existing one, so it is recommended that you run ndk-build to create your own .so files.
When I used ndk-build in tess-two directory it just compiles and .so files are created.
How can you include native libraries in gradle and this article describes android studio: Add pre-built .so files in project using Android gradle plugin 0.7.3
source to share
This works for me: https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle
But don't delete the libs directory!
Set the compileSdkVersion
, buildToolsVersion
, minSdkVersion
and targetSdkVersio
at the same meanings as in the projectbuil.gradle
I also change classpath 'com.android.tools.build:gradle:0.9.+'
toclasspath 'com.android.tools.build:gradle:1.0.+'
source to share
At some point Android Studio suggests to install
jni.srcDirs = []
leading to the following source kits in 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 the correct src path entered here, this valid work
source to share
I'm not sure if it works for you, but in my case, here's what I did:
1. In common.h: change#include <allheaders.h>
to
#include <src/src/allheaders.h>
. 2. In your 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']
}
}
source to share
Ppl, After the battle of the day .. finally got a solution
In the build.gradle of the tess-two module, add the following 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']
}
Most importantly, please check manually that all those file paths given in the above code exist in the tess-two module !!
Check in which path "liblept.so" and others "so" files exist in library tess-two. For me it was inside / tesstwo / src / main / jniLibs / armeabi -v7a. Hence, I did jniLibs.srcDirs = ['src / main / jniLibs'] in the above code. Hope this helps!
source to share