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 !!
Related
I have a Android project which uses libraries with interdependencies:
Android Application depends on the following native libraries
module tess-two (containing tesseract and leptonica)
module opencv4android
module mylibrary
mylibrary also depends on tess-two and opencv4android
The following is the build.gradle file of my Android Application:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':libraries:opencv4android')
compile project(':libraries:tess-two')
compile project(':libraries:mylibrary')
}
android {
compileSdkVersion 19
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
// packagingOptions {
// exclude 'lib/armeabi/liblept.so'
// exclude 'lib/armeabi/libtess.so'
// exclude 'lib/armeabi-v7a/liblept.so'
// exclude 'lib/armeabi-v7a/libtess.so'
// exclude 'lib/mips/liblept.so'
// exclude 'lib/mips/libtess.so'
// exclude 'lib/x86/liblept.so'
// exclude 'lib/x86/libtess.so'
// }
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
A gradle build on this configuration fails with duplicate files during packaging of APK error due to liblept.so and libtess.so being copied twice.
When I uncomment the packaging options I can build successfully, however, I get an UnsatisfiedLinkError at runtime since liblept.so and libtess.so are not contained in the apk at all.
How can I get liblept.so and libtess.so to be included in the apk exactly once?
I think I found the solution, however, I do not quite understand it.
The build.gradle files of both modules mylibrary and tess-two contained a definition for
android.sourceSets.main.jniLibs.srcDirs = ['libs']
Commenting this definition in tess-two resulted in libtess.soand liblept.so being copied to the apk only once.
If someone understands this solution please leave a comment or answer.
Edit:
In the meantime I found a better solution:
I added the following code to my main applications gradle.build file:
packagingOptions { // otherwise libtess.so and liblept.so are copied to apk twice resulting in an error
pickFirst('lib/*/liblept.so')
pickFirst('lib/*/libtess.so')
}
i have a prebuilt libraries that contains jar files and .so files and i newly converted my project from eclipse to android studio
my libs directory in eclipse is
libs
****armeabi
****x86
****jar files
so armeabi and x86 contains the .so files and when i converted project to android studio the app build very well at first but some classes in the .so files are not initialized and giving error
java.lang.ExceptionInInitializerError
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load nmsp_speex from loader dalvik.system.PathClassLoader[dexPath=/data/app/project.app-2.apk,libraryPath=/data/app-lib/project.app-2]: findLibrary returned null
and i searched about this error , people says that you must add .so files in jni folder and a already did that ad found build error when android studio tried to build the ndk and the error says
Error:Execution failed for task ':project:compileDebugNdk'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'E:\Android Index\android-ndk-r10d\ndk-build.cmd'' finished with non-zero exit value 1
and here is my build.gradle file
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':appcompat')
compile project(':facebook')
compile project(':google-play-services_lib')
compile project(':main')
compile project(':pagerslidingtabstrip')
compile 'com.android.support:multidex:1.0.0'
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.0"
defaultConfig
{
minSdkVersion 9
targetSdkVersion 21
multiDexEnabled true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jni.srcDirs = ['src/main/jni', 'src/main/jni/']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
so any help on this
if you don't have any NDK source code inside your project (you're not generating the .so files, you're only using them), then remove the jni folder and put your .so files into src/main/jniLibs/armeabi and src/main/jniLibs/x86.
btw you placed your ndk directory under a path that contains a space. You should move it to somewhere else or delete this blank space.
I had the same issue.I placed my .so files under
src->
main->
jniLibs->armeabi-> .so file
and removed the line containing
jni.srcDirs = ['src/main/jni', 'src/main/jni/']
from my app's build.gradle.And it works fine.
Hope this helps someone.
I am currently attempting to switch my project over to using gradle builds. While using the old build system I linked to the private/internal/hidden android API's by compiling the source and linking the classes.jar files before the Android libraries. I am currently trying to do the same thing in gradle with no luck at all.
With my current build.gradle file I receive the following error:
Gradle: A problem occurred evaluating project ':Launcher2'.
> Could not find method external() for arguments [file collection] on project ':Launcher2'.
If I remove these lines before "apply plugin: android"
dependencies {
compile files('libraries/classes.jar')
}
I receive errors about missing com.android.internal and com.android.common packages which are located in my classes.jar file.
Here's my build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
dependencies {
compile files('libraries/classes.jar')
}
plugin: 'android'
android {
buildToolsVersion "17.0"
compileSdkVersion 10
dependencies {
compile fileTree(dir: 'libraries', include: '*.jar')
compile project(':ActiveAndroid')
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Edit: After reading the gradle documentation a bit more I was able to successfully link the libraries into the project but the order of dependencies is wrong. The equivalent to what I am trying to do is adding both .jar files to the top of the classpath so that they are declared before the android SDK jar files.
I was digging through the source for the android gradle plugin, it seems that this may not be possible. The code seems incomplete and will not build. If anyone has any insight I would really appreciate it. Otherwise it looks like I will have to switch back to using Ant for now.
I'm trying to switch from eclipse to android studio for my android development.
However, I still haven't found the right way to import my existing project.
I don't know if it is important: but I'm using a mac
I did the export step in eclipse, imported this gradle build in Android Studio, but when I try to build my project, it gives me this error:
Gradle:
FAILURE: Could not determine which tasks to execute.
* What went wrong:
Task 'assembleDebug' not found in project ':ProjectName'.
* Try:
Run gradle tasks to get a list of available tasks.
Could not execute build using Gradle installation '/Users/<username>/Development/Build/gradle-1.6'.
This is the build.gradle file that eclipse gave me:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.+'
}
}
apply plugin: 'android'
dependencies {
compile project(':ProjectName:library:ActionBarSherlock')
compile project(':ProjectName:library:facebook')
compile files('../../../../../../../ProjectName/libs/gcm.jar')
compile files('../../../../../../../ProjectName/libs/libGoogleAnalyticsV2.jar')
compile files('../../../../../../../ProjectName/libs/commons-lang3-3.1.jar')
compile files('../../../../../../../ProjectName/libs/actionbarsherlock-plugin-maps-4.2.0.jar')
compile files('../../../../../../../NiteOwl/libs/volley.jar')
compile project(':ProjectName:library:PullToRefresh')
compile project(':ProjectName:library:google-play-services_lib')
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
I've seen a lot of possible solutions, but none of them worked for me, any idea what I'm doing wrong?
The path to the project has no spaces in it
jar libraries => ProjectName/libs
android libraries => ProjectName/library
all of this was working in eclipse
We recently moved our project to gradle as well. We ran into issues due to the library projects.
To solve it we added a settings.gradle file in the root of your project with
include ':libs:actionbarsherlock'
include ':yourprojectname'
Add all your library projects from eclipse into the settings.gradle
We also made a build.gradle file for each of the library Projects.
AFAIK the export from eclipse doesn't deal well with library projects.
In the build.gradle at the root of your project (the one that's probably mostly empty), add the following line:
task assemble{}
Found at https://code.google.com/p/android/issues/detail?id=57531
I've had this error appear when I had a stray empty flavors stanza in my build.gradle:
productFlavors {
}
I'm using new Android studio, based on IDEA, and trying to build project with ABS library in dependencies for the main module.
And I'm getting errors:
Gradle: package com.actionbarsherlock.app does not exist
Gradle: cannot find symbol class SherlockActivity
Gradle: package com.actionbarsherlock.view does not exist
Gradle: cannot find symbol variable super
Gradle: cannot find symbol method setContentView(int)
....
Why and how to fix it?
I used build ok.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 7
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
I was putting this as a comment because I wasn't sure if its your exact issue but it looks like abs isn't added as a module correctly. So I added as an answer
Try download abs fresh, extract it then in Android Studio - file > import module... and import the actionbarsherlock directory. After this however I had a error relating to junit so check the last steps in below post
Follow the steps here: Problems importing project into Android Studio regarding ActionBarSherlock
That post isn't your exact issue but the steps got abs working for me. so try that within your existing project
I did the import module, but i still had to add ActionBarSherlock as a dependency and then that got it working.
(actually i had the toplevel exception for mismatched support libs too, but then i got it working)