gpt4 book ai didi

android-studio - tesseract dlopen在android studio中失败

转载 作者:行者123 更新时间:2023-12-03 04:34:27 24 4
gpt4 key购买 nike

我已经下载了最新的tesseract(tess-two),我遵循了大多数在互联网上写的如何将libs与项目集成的方法,但是我注意到最新的tess-two版本在build.gradle中具有与ndk-bulid相关的文件,因此建立我留给android studio的libarires,所谓的成功。这是tess-two的build.gradle:

  import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.library'


android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
jni.srcDirs = []
jniLibs.srcDirs = ['libs']

}
}

// Call external ndk-build(.cmd) script to build the native code
task ndkBuild(type: Exec) {
def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
commandLine "${android.ndkDirectory}/ndk-build${ndkBuildExt}",
'-C', file('.').absolutePath,
'-j', Runtime.runtime.availableProcessors()
}

tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}

// Cleanup task to remove previously generated binaries
task ndkClean(type: Exec) {
def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
commandLine "${android.ndkDirectory}/ndk-build${ndkBuildExt}",
'-C', file('.').absolutePath, 'clean'
}

tasks.withType(Delete) {
cleanTask -> cleanTask.dependsOn ndkClean
}
}

dependencies {
compile 'com.github.dcendents:android-maven-plugin:1.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
}


// Settings for uploading module AAR to Bintray for library distribution

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
options {
links "http://docs.oracle.com/javase/7/docs/api/"
linksOffline "http://d.android.com/reference","${android.sdkDirectory}/docs/reference"
}
}


task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives javadocJar
archives sourcesJar
}



Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

这是构建日志:
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:libraries:tess-two:preBuild UP-TO-DATE
:libraries:tess-two:preReleaseBuild UP-TO-DATE
:libraries:tess-two:compileReleaseNdk UP-TO-DATE
:libraries:tess-two:compileLint
:libraries:tess-two:copyReleaseLint UP-TO-DATE
:libraries:tess-two:mergeReleaseProguardFiles UP-TO-DATE
:libraries:tess-two:packageReleaseRenderscript UP-TO-DATE
:libraries:tess-two:checkReleaseManifest
:libraries:tess-two:prepareReleaseDependencies
:libraries:tess-two:compileReleaseRenderscript UP-TO-DATE
:libraries:tess-two:generateReleaseResValues UP-TO-DATE
:libraries:tess-two:generateReleaseResources UP-TO-DATE
:libraries:tess-two:packageReleaseResources UP-TO-DATE
:libraries:tess-two:compileReleaseAidl UP-TO-DATE
:libraries:tess-two:generateReleaseBuildConfig UP-TO-DATE
:libraries:tess-two:generateReleaseAssets UP-TO-DATE
:libraries:tess-two:mergeReleaseAssets UP-TO-DATE
:libraries:tess-two:processReleaseManifest UP-TO-DATE
:libraries:tess-two:processReleaseResources UP-TO-DATE
:libraries:tess-two:generateReleaseSources UP-TO-DATE
:libraries:tess-two:ndkBuild
make: Entering directory `/Users/sieciech/AndroidStudioProjects/OCRTestDwa/libraries/tess-two'
[armeabi] Install : libjpeg.so => libs/armeabi/libjpeg.so
[armeabi] Install : liblept.so => libs/armeabi/liblept.so
[armeabi] Install : libpng.so => libs/armeabi/libpng.so
[armeabi] Install : libtess.so => libs/armeabi/libtess.so
[armeabi-v7a] Install : libjpeg.so => libs/armeabi-v7a/libjpeg.so
[armeabi-v7a] Install : liblept.so => libs/armeabi-v7a/liblept.so
[armeabi-v7a] Install : libpng.so => libs/armeabi-v7a/libpng.so
[armeabi-v7a] Install : libtess.so => libs/armeabi-v7a/libtess.so
[x86] Install : libjpeg.so => libs/x86/libjpeg.so
[x86] Install : liblept.so => libs/x86/liblept.so
[x86] Install : libpng.so => libs/x86/libpng.so
[x86] Install : libtess.so => libs/x86/libtess.so
[mips] Install : libjpeg.so => libs/mips/libjpeg.so
[mips] Install : liblept.so => libs/mips/liblept.so
[mips] Install : libpng.so => libs/mips/libpng.so
[mips] Install : libtess.so => libs/mips/libtess.so
[arm64-v8a] Install : libjpeg.so => libs/arm64-v8a/libjpeg.so
[arm64-v8a] Install : liblept.so => libs/arm64-v8a/liblept.so
[arm64-v8a] Install : libpng.so => libs/arm64-v8a/libpng.so
[arm64-v8a] Install : libtess.so => libs/arm64-v8a/libtess.so
[x86_64] Install : libjpeg.so => libs/x86_64/libjpeg.so
[x86_64] Install : liblept.so => libs/x86_64/liblept.so
[x86_64] Install : libpng.so => libs/x86_64/libpng.so
[x86_64] Install : libtess.so => libs/x86_64/libtess.so
[mips64] Install : libjpeg.so => libs/mips64/libjpeg.so
[mips64] Install : liblept.so => libs/mips64/liblept.so
[mips64] Install : libpng.so => libs/mips64/libpng.so
[mips64] Install : libtess.so => libs/mips64/libtess.so
make: Leaving directory `/Users/sieciech/AndroidStudioProjects/OCRTestDwa/libraries/tess-two'
:libraries:tess-two:compileReleaseJavaWithJavac UP-TO-DATE
:libraries:tess-two:processReleaseJavaRes UP-TO-DATE
:libraries:tess-two:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
:libraries:tess-two:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE
:libraries:tess-two:mergeReleaseJniLibFolders UP-TO-DATE
:libraries:tess-two:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE
:libraries:tess-two:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE
:libraries:tess-two:bundleRelease UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2311Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareOCRTestDwaLibrariesTessTwoUnspecifiedLibrary UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:transformClassesWithDexForDebug UP-TO-DATE
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug UP-TO-DATE
:app:zipalignDebug UP-TO-DATE
:app:assembleDebug UP-TO-DATE
Information:BUILD SUCCESSFUL
Information:Total time: 4.991 secs
Information:0 errors
Information:0 warnings
Information:See complete output in console

在我的索尼xperia上运行应用程序后,很不幸,我遇到了以下异常:
22:05:04.097 17868-17868/com.example.sieciech.ocrtestdwa E/dalvikvm: dlopen("/data/app-lib/com.example.sieciech.ocrtestdwa-2/liblept.so") failed: dlopen failed: cannot locate symbol "png_set_longjmp_fn" referenced by "liblept.so"...
02-09 22:05:04.097 17868-17868/com.example.sieciech.ocrtestdwa W/dalvikvm: Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI;
02-09 22:05:04.097 17868-17868/com.example.sieciech.ocrtestdwa D/AndroidRuntime: Shutting down VM
02-09 22:05:04.097 17868-17868/com.example.sieciech.ocrtestdwa W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4164fd88)
02-09 22:05:04.107 17868-17868/com.example.sieciech.ocrtestdwa E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sieciech.ocrtestdwa, PID: 17868
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "png_set_longjmp_fn" referenced by "liblept.so"...
at java.lang.Runtime.loadLibrary(Runtime.java:364)
at java.lang.System.loadLibrary(System.java:526)
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:44)
at com.example.sieciech.ocrtestdwa.MainActivity.onCreate(MainActivity.java:59)
at android.app.Activity.performCreate(Activity.java:5240)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2216)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2301)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5212)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)

使用随 nm一起提供的 android ndk工具,我看到:
nm: ./x86_64/liblept.so: no symbols

但是 readelf:
readelf -a ./x86_64/liblept.so | grep png_set_longjmp_fn
00000027add0 084900000007 R_X86_64_JUMP_SLO 0000000000000000 png_set_longjmp_fn + 0

当我查看libs / x86_64或libs / armXX或libs / mips时,都没有关系,对于nm来说我始终没有任何符号,对于readelf我得到的输出如上所述。

我打开了apk文件,所有库都在那里。

有什么想法我要做什么才能正常工作?

最佳答案

通过执行git pull并重建来更新您的OCR库。发生此错误是由于Android 4.4在运行时使用了其libpng版本而不是OCR库中可用的版本。 (显然,这仅是Android 4.4上的问题,而不是其他版本的Android上的问题。)在新版本的OCR库中,libpng已重命名为libpngt来解决此崩溃问题并在Android 4.4上正常运行

关于android-studio - tesseract dlopen在android studio中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35302278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com