不满意的链接错误:找不到本机方法:kdu_jni

时间:2015-06-08 10:04:11

标签: java android native

我将kdu_jni.jar文件导入为外部jar。该库是本机编码的。当我使用JAVA项目时,它可以工作,但Android不接受这个'方法。

package com.jp2.pathology;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import kdu_jni.Jp2_threadsafe_family_src;

import com.jp2.view.jpip.JPIPResponse;
import com.jp2.view.jpip.JPIPSocket;
import com.jp2.view.kakadu.JHV_KduException;
import com.jp2.view.kakadu.JHV_Kdu_cache;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;


public class MainActivity extends Activity {

    private ImageView mainImg; 

    private JPIPSocket socket;
    private URI uri;

    private JHV_Kdu_cache cache;
    private static File cachePath;

    private Jp2_threadsafe_family_src familySrc = new Jp2_threadsafe_family_src();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mainImg = (ImageView) findViewById(R.id.main_img);

        try {
            try {
                connect();
            } catch (JHV_KduException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void connect() throws IOException, JHV_KduException{
        JPIPResponse res;
        socket = new JPIPSocket();

        try {
            uri = new URI("jpip://192.168.1.71:3312");
            res = (JPIPResponse) socket.connect(uri);
            String jpipTargetID;

            if (res.getHeader("JPIP-tid") == null)
                throw new JHV_KduException("The target id was not sent by the server");
            else
                jpipTargetID = res.getHeader("JPIP-tid");

            if (jpipTargetID.contains("/")) {
                jpipTargetID = jpipTargetID.substring(jpipTargetID.lastIndexOf("/") + 1);
            }

            cache = new JHV_Kdu_cache(jpipTargetID, cachePath);
            cache.addJPIPResponseData(res);

            Log.d("CACHE", cache.toString());

        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}

这是错误:

  

06-08 12:44:09.901:E / AndroidRuntime(7638):致命异乎寻常:主要   06-08 12:44:09.901:E / AndroidRuntime(7638):流程:   com.jp2.pathology,PID:7638 06-08 12:44:09.901:   E / AndroidRuntime(7638):java.lang.UnsatisfiedLinkError:Native方法   找不到:kdu_jni.Jp2_family_src.Native_init_class :()V 06-08   12:44:09.901:E / AndroidRuntime(7638):at   kdu_jni.Jp2_family_src.Native_init_class(原生方法)06-08   12:44:09.901:E / AndroidRuntime(7638):at   kdu_jni.Jp2_family_src。(Jp2_family_src.java:6)06-08   12:44:09.901:E / AndroidRuntime(7638):at   com.jp2.pathology.MainActivity。(MainActivity.java:33)06-08   12:44:09.901:E / AndroidRuntime(7638):at   java.lang.Class.newInstanceImpl(Native Method)06-08 12:44:09.901:   E / AndroidRuntime(7638):at   java.lang.Class.newInstance(Class.java:1208)06-08 12:44:09.901:   E / AndroidRuntime(7638):at   android.app.Instrumentation.newActivity(Instrumentation.java:1067)   06-08 12:44:09.901:E / AndroidRuntime(7638):at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2297)   06-08 12:44:09.901:E / AndroidRuntime(7638):at   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)   06-08 12:44:09.901:E / AndroidRuntime(7638):at   android.app.ActivityThread.access $ 900(ActivityThread.java:175)06-08   12:44:09.901:E / AndroidRuntime(7638):at   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1308)   06-08 12:44:09.901:E / AndroidRuntime(7638):at   android.os.Handler.dispatchMessage(Handler.java:102)06-08   12:44:09.901:E / AndroidRuntime(7638):at   android.os.Looper.loop(Looper.java:146)06-08 12:44:09.901:   E / AndroidRuntime(7638):at   android.app.ActivityThread.main(ActivityThread.java:5602)06-08   12:44:09.901:E / AndroidRuntime(7638):at   java.lang.reflect.Method.invokeNative(Native Method)06-08   12:44:09.901:E / AndroidRuntime(7638):at   java.lang.reflect.Method.invoke(Method.java:515)06-08 12:44:09.901:   E / AndroidRuntime(7638):at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1283)   06-08 12:44:09.901:E / AndroidRuntime(7638):at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)06-08   12:44:09.901:E / AndroidRuntime(7638):at   dalvik.system.NativeStart.main(原生方法)

如何将原生jar库导入Android Project?

1 个答案:

答案 0 :(得分:0)

问题是您包含的jar依赖于Android SDK中不可用的Java方法。

你应该明白,即使Android程序是用Java编写的,它们也不是由JVM运行的。