[英]Android : java.lang.UnsatisfiedLinkError…couldn't find “lib…”
I have followed building instructions for AndroidScannerDemo on Github . 我已遵循Github上关于AndroidScannerDemo的构建说明。 I build AndroidScannerDemo successfully.
我成功构建了AndroidScannerDemo。 Then I want to develop this application by imported the OCR library from SimpleTesseractExample on Github .
然后,我想通过从Github上的 SimpleTesseractExample导入OCR库来开发此应用程序。 I am trying to run the test application.
我正在尝试运行测试应用程序。 The application can start but when i try to access camera and gallery mode it gives the following exception:
该应用程序可以启动,但是当我尝试访问摄像头和图库模式时,它将出现以下异常:
Error in testRunner: testRunner中的错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.scanner.demo, PID: 2715
java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-support-annotations-23.2.1_3e4fb588ccc5090e3d7674f4d618c6c58911a463-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-internal_impl-23.2.1_95668bb7e1c637bd79cf411dae8840e187175822-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-com.rmtheis-tess-two-5.4.1_e5cb86e300070c39241b9a43567ee2efb208d508-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.2.1_6c016aaa8587fb0461cb7e32ce3f36bda91ced6b-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-com.android.support-support-v4-23.2.1_387cf51515861ffabd82d96d9419f72e885ab771-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-com.android.support-appcompat-v7-23.2.1_8d29c9636ac8f816df67405c13d3515c565cd287-classes.dex", dex file "/data/data/com.scanner.demo/files/instant-run/dex/slice-com.android.support-animated-vector-drawable-23.2.1_96909a566032fc8bdb0819e184295a7955082571-classes.dex"],nativeLibraryDirectories=[/data/app/com.scanner.demo-2/lib/x86_64, /system/fake-libs64, /data/app/com.scanner.demo-2/base.apk!/lib/x86_64, /system/lib64, /vendor/lib64]]] couldn't find "libopencv_java3.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:984)
at java.lang.System.loadLibrary(System.java:1530)
at com.scanlibrary.ScanActivity.<clinit>(ScanActivity.java:73)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
It occur when I add this line in to the build.gradle in dependencies part 当我将此行添加到依赖项部分的build.gradle中时,会发生这种情况
compile 'com.rmtheis:tess-two:5.4.1'
MainActivity Code: MainActivity代码:
package com.scanner.demo;
import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.scanlibrary.ScanActivity;
import com.scanlibrary.ScanConstants;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.googlecode.tesseract.android.TessBaseAPI; //OCR
public class MainActivity extends ActionBarActivity {
private static final int REQUEST_CODE = 99;
private Button scanButton;
private Button cameraButton;
private Button mediaButton;
private ImageView scannedImageView;
//----------- OCR PART --------
private TessBaseAPI mTess;
String datapath = "";
Bitmap image;
//-----------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
//----------- OCR PART --------
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//init image
image = BitmapFactory.decodeResource(getResources(), R.id.scannedImage);
//initialize Tesseract API
String language = "eng";
datapath = getFilesDir()+ "/tesseract/";
mTess = new TessBaseAPI();
checkFile(new File(datapath + "tessdata/"));
mTess.init(datapath, language);
//-----------------------------
}
private void init() {
scanButton = (Button) findViewById(R.id.scanButton);
scanButton.setOnClickListener(new ScanButtonClickListener());
cameraButton = (Button) findViewById(R.id.cameraButton);
cameraButton.setOnClickListener(new ScanButtonClickListener(ScanConstants.OPEN_CAMERA));
mediaButton = (Button) findViewById(R.id.mediaButton);
mediaButton.setOnClickListener(new ScanButtonClickListener(ScanConstants.OPEN_MEDIA));
scannedImageView = (ImageView) findViewById(R.id.scannedImage);
}
private class ScanButtonClickListener implements View.OnClickListener {
private int preference;
public ScanButtonClickListener(int preference) {
this.preference = preference;
}
public ScanButtonClickListener() {
}
@Override
public void onClick(View v) {
startScan(preference);
}
}
protected void startScan(int preference) {
Intent intent = new Intent(this, ScanActivity.class);
intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, preference);
startActivityForResult(intent, REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri uri = data.getExtras().getParcelable(ScanConstants.SCANNED_RESULT);
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
getContentResolver().delete(uri, null, null);
scannedImageView.setImageBitmap(bitmap);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
private Bitmap convertByteArrayToBitmap(byte[] data) {
return BitmapFactory.decodeByteArray(data, 0, data.length);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
//----------- OCR PART --------
public void processImage(View view){
String OCRresult = null;
mTess.setImage(image);
OCRresult = mTess.getUTF8Text();
TextView OCRTextView = (TextView) findViewById(R.id.OCRTextView);
OCRTextView.setText(OCRresult);
}
private void checkFile(File dir) {
if (!dir.exists()&& dir.mkdirs()){
copyFiles();
}
if(dir.exists()) {
String datafilepath = datapath+ "/tessdata/eng.traineddata";
File datafile = new File(datafilepath);
if (!datafile.exists()) {
copyFiles();
}
}
}
private void copyFiles() {
try {
String filepath = datapath + "/tessdata/eng.traineddata";
AssetManager assetManager = getAssets();
InputStream instream = assetManager.open("tessdata/eng.traineddata");
OutputStream outstream = new FileOutputStream(filepath);
byte[] buffer = new byte[1024];
int read;
while ((read = instream.read(buffer)) != -1) {
outstream.write(buffer, 0, read);
}
outstream.flush();
outstream.close();
instream.close();
File file = new File(filepath);
if (!file.exists()) {
throw new FileNotFoundException();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//-----------------------------
}
Can anyone help me please... Thanks in advance. 任何人都可以帮我...预先感谢。
PS.It will be good if the advice is step by step.Because I don't have much experience about android-studio before. PS。如果建议是循序渐进的,那会很好。因为我之前对android-studio没有太多经验。 Even though i tryhard to study it but i still don't understand in some case.
即使我努力研究它,但在某些情况下我还是不明白。
This might have to do with resolving methods between the scanlibray project and your app. 这可能与scanlibray项目和您的应用程序之间的解析方法有关。 Below describes how to import an existing project and utilize its Classes.
下面介绍了如何导入现有项目并利用其类。
Give this a shot. 试一下。
In your settings.gradle
file under your scanlibrary
, change include ':app', ':scanlibrary'
to include ':scanlibrary', ':app'
. 在您的
scanlibrary
下的settings.gradle
文件中,将include ':app', ':scanlibrary'
更改为include ':scanlibrary', ':app'
。
Then, in your app
project, open build.gradle
, under dependencies add, complie project (':scanlibrary')
然后,在您的
app
项目中,打开build.gradle
,在依赖项下add complie project (':scanlibrary')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.