问题
I have build the project vie steps in the git download page https://github.com/rmtheis/tess-two#build I have installed ndk/sdk an configured in my path environment, also i have add ndk path in project local.properties. Here is my project build log, after i had add the tess-two lib as externel project into my
Information:Gradle tasks [clean, :app:compileDebugSources, :app:compileDebugAndroidTestSources, :tesstwo:compileDebugSources, :tesstwo:compileDebugAndroidTestSources]
:app:clean
:tesstwo:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:tesstwo:compileLint
:tesstwo:copyReleaseLint UP-TO-DATE
:tesstwo:mergeReleaseProguardFiles UP-TO-DATE
:tesstwo:preBuild UP-TO-DATE
:tesstwo:preReleaseBuild UP-TO-DATE
:tesstwo:checkReleaseManifest
:tesstwo:prepareReleaseDependencies
:tesstwo:compileReleaseAidl
:tesstwo:compileReleaseRenderscript
:tesstwo:generateReleaseBuildConfig
:tesstwo:generateReleaseAssets UP-TO-DATE
:tesstwo:mergeReleaseAssets
:tesstwo:generateReleaseResValues UP-TO-DATE
:tesstwo:generateReleaseResources
:tesstwo:packageReleaseResources
:tesstwo:processReleaseManifest
:tesstwo:processReleaseResources
:tesstwo:generateReleaseSources
:tesstwo:processReleaseJavaRes UP-TO-DATE
:tesstwo:compileReleaseJava
:tesstwo:packageReleaseJar
:tesstwo:compileReleaseNdk
In file included from C:\Users\Julian\AndroidStudioProjects\Jtess\tesstwo\src\main\jni\com_googlecode_leptonica_android\box.cpp:17:0:
C:\Users\Julian\AndroidStudioProjects\Jtess\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.exe: *** [C:\Users\Julian\AndroidStudioProjects\Jtess\tesstwo\build\intermediates\ndk\release\obj/local/arm64-v8a/objs/tesstwo/C_\Users\Julian\AndroidStudioProjects\Jtess\tesstwo\src\main\jni\com_googlecode_leptonica_android\box.o] Error 1
Error:Execution failed for task ':tesstwo:compileReleaseNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Julian\Downloads\android-ndk-r10d\ndk-build.cmd'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 38.843 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
回答1:
The steps you followed to compile Tesseract OCR works only on eclipse, If you want to use it on Android Studio, follow these steps
1) Download and install the ndk from here https://developer.android.com/tools/sdk/ndk/index.html. I had some trouble with its path in following steps so i put it in “C:\”.
2) Add that path to environment variables of the system (eg: “C:\android_ndk_r10d”) and then reboot so your machine can find it.
3) Download “tess-two-master” from here https://github.com/rmtheis/tess-two, extract it (for example in “C:\”) and rename it in “tess”.
4) Open “tess” folder and then open “tess-two” folder. Click on a blank space while pressing the shift button and select “Open command window here”.
5) Write “ndk-build” and wait until it completes (about 20min).
6) Go back in the parent folder, select “eyes-two” folder and again click on a blank space while pressing the shift button in order to open the command window.
7) Write “ndk-build” and wait.
8) Write “android update project –target 1 –path C:\tess\tess-two”. Of course I assume your “tess” folder is located in “C:\”
9) Write “ant release”. IF IT COMPLAINS go where you change your system environment variables as you did in step 2 and ADD a new variable with name “JAVA_HOME” and value the path to your jdk (eg: “C:\Program Files\Java\jdk1.8.0_40″)
10) Open a completely new Android Studio project and follow these instructions https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle from section “Configure tess-two with gradle” but for safety don’t delete any folder or file even if he suggests to do so. I had some trouble with “build.gradle” file in “libraries\tess-two” directory, but it is sufficient to change some value on it. In my case I have:
“
classpath ‘com.android.tools.build:gradle:0.14.0′” instead of “classpath ‘com.android.tools.build:gradle:0.9.+’
”and
”
compileSdkVersion 21 buildToolsVersion “21.0.2” defaultConfig { minSdkVersion 15 targetSdkVersion 21 }
”
instead of
”
compileSdkVersion 19 buildToolsVersion “19.0.3” defaultConfig { minSdkVersion 8 targetSdkVersion 19}
”.
Note that the last step means you have to go in “File -> Project Structure -> Select a module from the left subwindow -> Dependencies (last tab) ->Press the green “+” on your right -> Module Dependency -> OK”
11) Download this project https://github.com/GautamGupta/Simple-Android-OCR and copy&paste in your new project the code in these files: “SimpleAndroidOCRActivity.java”, “main.xml”, “strings.xml”. Of course your files may have different names (in my case “MainActivity.java”, “activity_main.xml”, “strings.xml”) so some renaming in the code may be necessary. Also open your “AndroidManifest.xml” and add at the end (but before “/manifest”) what you find between “/application” and “/manifest” in the just downloaded “AndroidManifest.xml” (it means that you have to add “uses-permissions” and “uses-feature” tag).
12) Download from here https://code.google.com/p/tesseract-ocr/downloads/list the file in the language you prefer (eg: tesseract-ocr-3.02.eng.tar.gz ), extract it and locate the file “yourLanguage.traineddata” (eg: “eng.traineddata”). Forget for a moment your Android Studio IDE, open the folder of your project and go in “app–>src–>main”. Create here a new folder and name it “assets”. Open it and create another folder named “tessdata”. Put there your .traineddata file.
Source: http://gaut.am/making-an-ocr-android-app-using-tesseract/#comment-184181
回答2:
Before see the answer download latest "android ndk" and install or extract it on C:, folder path should be like this; "C:\android-ndk-r10e"
Then add the ndk path (C:\android-ndk-r10e) to the path variable's value in the environment variable(System variable) which left my "path" variable like this
Settings --> System --> Advenced System Settings --> System Variables
After set this settings you can follow the intsructions in the link below for Android Studio on Windows Operating Systems;
https://stackoverflow.com/a/30882613/1897454
回答3:
I had this problem. First of all You have to give your NDK path in local.properties of your app.
e.g. ndk.dir=/home/user/bin/android_ndk/android-ndk-r10e
Then in my build.gradle file I had something like this for calling ndk build command.
commandLine 'ndk-build', '-C', file('src/main/jni').absolutePath
I'v change it to
commandLine '/home/user/bin/android_ndk/android-ndk-r10e/ndk-build', '-C', file('src/main/jni').absolutePath
I gave full path of NDK build. Hope it'll help you.
来源:https://stackoverflow.com/questions/30727048/tess-two-import-in-android-sdk-build-error-in-windows