Android プロジェクトで JNetPcap ライブラリの使用にスタックしています。JNetPcap をプロジェクトのライブラリとして設定しても、このコードでネイティブ アプリケーションに到達できません。
誰かが私を助けることができますか?お願いします
私のコードは以下の通りです:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.List;
import org.jnetpcap.PcapIf;
import org.jnetpcap.packet.JMemoryPacket;
import org.jnetpcap.packet.JPacket;
import org.jnetpcap.protocol.JProtocol;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Server_Android extends Activity{
private final static int SERVER_PORT = 1234;
// public final static int RECEIVING_TIMEOUT_SERVER = 3000;
DatagramSocket socket;
DatagramPacket packetOut;
DatagramPacket packetIn;
byte[] DataIn;
byte[] DataOut;
List<PcapIf> alldevs;
StringBuilder errbuf;
/*Android widgets*/
TextView text;
EditText edit;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_server_android);
//text = (EditText)
button =(Button)findViewById(R.id.button1);
edit = (EditText)findViewById(R.id.editText1);
text =(TextView)findViewById(R.id.textView2);
text.setText("");
handlingpacket();
/* Thread for receiving Data from CLient */
new Thread(new Message_handler()).start();
try {
Thread.sleep(500);
reply();
}catch(InterruptedException e){
Log.e("UDP", "UDP receive failed!");
}
}
//
public void handlingpacket(){
JPacket jmp = new JMemoryPacket(JProtocol.UDP_ID,
"001801bf 6adc0025 4bb7afec 08004500 "
+ " 0041a983 40004006 d69ac0a8 00342f8c "
+ " ca30c3ef 008f2e80 11f52ea8 4b578018 "
+ " ffffa6ea 00000101 080a152e ef03002a "
+ " 2c943538 322e3430 204e4f4f 500d0a");
text.append("" + jmp);
}
//
public class Message_handler implements Runnable{
public Message_handler(){}
public void run(){
try {
DataOut = new byte[1024];
while(true){
socket = new DatagramSocket(SERVER_PORT);
socket.setReuseAddress(true);
socket.setBroadcast(true);
// socket.setSoTimeout(RECEIVING_TIMEOUT_SERVER);
packetIn = new DatagramPacket(DataOut,DataOut.length);
socket.receive(packetIn);
runOnUiThread( new Runnable(){ // original thread for UI interactions
public void run(){
String message = new String(packetIn.getData());
text.append("Message " + message +"\n From :" + packetIn.getAddress() + " on port : "+ packetIn.getPort() +"\n");
Log.d("UDP", "le message reçu");
Log.d("Message : ", "" + message);
}
});
}
}
catch(UnknownHostException exc) {
exc.printStackTrace();
}
catch(SocketException exc) {
System.out.println("Problem openning socket");
}
catch(IOException exc) {
System.out.println("Problem in reception of messages");
}
socket.close();
}
}
public void reply(){
DataIn = new byte[1024];
button.setOnClickListener( new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
socket = new DatagramSocket();
String str = edit.getText().toString();
DataIn = str.getBytes();
packetOut = new DatagramPacket(DataIn, DataIn.length, packetIn.getAddress(), packetIn.getPort());
socket.send(packetOut);
}catch (SocketException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
ログファイル:
08-21 11:18:36.755: W/dalvikvm(776): No implementation found for native Lcom/slytechs/library/NativeLibrary;.dlopen (Ljava/lang/String;)J
08-21 11:18:36.755: W/dalvikvm(776): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/jnetpcap/nio/JMemory;
08-21 11:18:36.755: D/AndroidRuntime(776): Shutting down VM
08-21 11:18:36.755: W/dalvikvm(776): threadid=1: thread exiting with uncaught exception (group=0x40a2d1f8)
08-21 11:18:36.760: E/AndroidRuntime(776): FATAL EXCEPTION: main
08-21 11:18:36.760: E/AndroidRuntime(776): java.lang.ExceptionInInitializerError
08-21 11:18:36.760: E/AndroidRuntime(776): at com.example.server_android.Server_Android.handlingpacket(Server_Android.java:66)
08-21 11:18:36.760: E/AndroidRuntime(776): at com.example.server_android.Server_Android.onCreate(Server_Android.java:50)
08-21 11:18:36.760: E/AndroidRuntime(776): at android.app.Activity.performCreate(Activity.java:4465)
08-21 11:18:36.760: E/AndroidRuntime(776): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-21 11:18:36.760: E/AndroidRuntime(776): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
08-21 11:18:36.760: E/AndroidRuntime(776): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
08-21 11:18:36.760: E/AndroidRuntime(776): at android.app.ActivityThread.access$600(ActivityThread.java:132)
08-21 11:18:36.760: E/AndroidRuntime(776): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
08-21 11:18:36.760: E/AndroidRuntime(776): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 11:18:36.760: E/AndroidRuntime(776): at android.os.Looper.loop(Looper.java:137)
08-21 11:18:36.760: E/AndroidRuntime(776): at android.app.ActivityThread.main(ActivityThread.java:4575)
08-21 11:18:36.760: E/AndroidRuntime(776): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 11:18:36.760: E/AndroidRuntime(776): at java.lang.reflect.Method.invoke(Method.java:511)
08-21 11:18:36.760: E/AndroidRuntime(776): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
08-21 11:18:36.760: E/AndroidRuntime(776): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
08-21 11:18:36.760: E/AndroidRuntime(776): at dalvik.system.NativeStart.main(Native Method)
08-21 11:18:36.760: E/AndroidRuntime(776): Caused by: java.lang.UnsatisfiedLinkError: dlopen
08-21 11:18:36.760: E/AndroidRuntime(776): at com.slytechs.library.NativeLibrary.dlopen(Native Method)
08-21 11:18:36.760: E/AndroidRuntime(776): at com.slytechs.library.NativeLibrary.<init>(Unknown Source)
08-21 11:18:36.760: E/AndroidRuntime(776): at com.slytechs.library.JNILibrary.<init>(Unknown Source)
08-21 11:18:36.760: E/AndroidRuntime(776): at com.slytechs.library.JNILibrary.loadLibrary(Unknown Source)
08-21 11:18:36.760: E/AndroidRuntime(776): at com.slytechs.library.JNILibrary.register(Unknown Source)
08-21 11:18:36.760: E/AndroidRuntime(776): at com.slytechs.library.JNILibrary.register(Unknown Source)
08-21 11:18:36.760: E/AndroidRuntime(776): at com.slytechs.library.JNILibrary.register(Unknown Source)
08-21 11:18:36.760: E/AndroidRuntime(776): at org.jnetpcap.nio.JMemory.<clinit>(Unknown Source)
08-21 11:18:36.760: E/AndroidRuntime(776): ... 16 more