5

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?

Aadil Keshwani
  • 1,385
  • 1
  • 18
  • 29
Michael
  • 53
  • 1
  • 3
  • Just to mention - the path in the error message does NOT match the patch you cite "/src/src" – PorridgeBear Jan 15 '15 at 23:51
  • Sorry if it was not clear, but the error occurred in common.h, but the allheaders.h file it's looking for (at least what I suspect) is in the "/src/src" folder. – Michael Jan 16 '15 at 01:26
  • What operating system are you using, and which version of the Android NDK are you using? Did you follow the build instructions _exactly_? At what point do you see this error? – rmtheis Jan 17 '15 at 15:51
  • I'm running OS X 10.9.5; I'm using android-ndk-r10d; So, I did deviate from the instructions at one point. On the command `android update project --path .` It said that it didn't know which project to set and recommended an additional tag which I found the solution to on another StackOverflow. Following this, because I'm not using Eclipse, I assumed Eclipse projects are similar to IntelliJ modules, so I used `Import Module` and added the module to my project. When I start writing Java code, this is where the error happens. Thanks – Michael Jan 20 '15 at 01:58

5 Answers5

1

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

Community
  • 1
  • 1
Anders Asplund
  • 575
  • 2
  • 7
1

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.+'

Macek_82
  • 11
  • 1
1

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

b00n12
  • 1,428
  • 1
  • 12
  • 16
0

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']

    }
}
thu tran
  • 13
  • 1
  • 4
0

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 !!

Srikanth P
  • 1,506
  • 14
  • 12