[英]Missing allheaders.h in Android Studio Project
I am following the tutorial from this tesseract tutorial and had everything go smoothly up until my actual running of the Java code. 我正在按照这个tesseract教程中的教程进行操作,并且在我实际运行Java代码之前一切顺利。 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. 我查看了/jni/com_googlecode_leptonica_android/src/src
并在那里找到allheaders.h
文件。 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. 我也遇到过Android Studio这个问题。 After googling some more i found this issue. 谷歌搜索后,我发现了这个问题。 https://code.google.com/p/android/issues/detail?id=74132 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. 显然,NDK插件会生成自己的Android.mk文件,并忽略任何现有的文件,因此推荐的方法是运行ndk-build来生成本机.so文件。
When I used ndk-build in the tess-two directory it compiles just fine and the .so files is created. 当我在tess-two目录中使用ndk-build时,它编译得很好并且创建了.so文件。
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 本文将介绍如何在gradle和android studio中包含本机库: 使用Android Gradle插件0.7.3在项目中添加预先构建的.so文件
This works for me: https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle 这对我有用 : https : //coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle
But do not delete libs directory! 但是不要删除libs目录!
Set compileSdkVersion
, buildToolsVersion
, minSdkVersion
and targetSdkVersio
to the same values as in project buil.gradle
将compileSdkVersion
, buildToolsVersion
, minSdkVersion
和targetSdkVersio
设置为与项目buil.gradle
相同的值
I also change classpath 'com.android.tools.build:gradle:0.9.+'
to classpath 'com.android.tools.build:gradle:1.0.+'
我还将classpath 'com.android.tools.build:gradle:0.9.+'
更改为classpath 'com.android.tools.build:gradle:1.0.+'
At some point Android Studio suggests to set jni.srcDirs = []
在某些时候Android Studio建议设置jni.srcDirs = []
leading to following sourceSets in the gradle.build of my tess-two library project 导致在我的tess-two库项目的gradle.build中跟随sourceSets
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 在这里输入正确的src路径,这个实际工作
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>
.
1.在common.h中:将#include <allheaders.h>
更改为#include <src/src/allheaders.h>
。
2. In the library project build.gradle: add this
2.在库项目build.gradle中:添加此项
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 Ppl,经过一天的努力......终于得到了解决方案
In build.gradle of tess-two module add the below code: 在build.gradle的tess-two模块中添加以下代码:
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!! 主要是请手动检查天气以上代码中指定的所有文件路径存在于tess-two模块!!
Check in which path "liblept.so" and other ".so" files exist in tess-two library. 检查tess-two库中存在“liblept.so”和其他“.so”文件的路径。 For me it was inside /tesstwo/src/main/jniLibs/armeabi-v7a . 对我来说,它位于/ tesstwo / src / main / jniLibs / armeabi-v7a中。 Hence i have made jniLibs.srcDirs = ['src/main/jniLibs'] in above code. 因此我在上面的代码中创建了jniLibs.srcDirs = ['src / main / jniLibs']。 Hope it helps !! 希望能帮助到你 !!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.