0
這裏是我的簡單測試程序UnsatisfiedLinkError:未發現本機方法:android.net.LocalSocketImpl.connectLocal
import java.io.IOException;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
public class TestAndroid
{
public TestAndroid() {
super();
}
private void run() throws IOException {
System.out.println("started");
LocalSocket ls = new LocalSocket();
System.out.println("connecting");
ls.connect(new LocalSocketAddress("blablabla"));
System.out.println("connected");
}
public static void main(String argv[])
{
try {
new TestAndroid().run();
} catch (Exception e) {
e.printStackTrace();
}
}
}
我使用Oracle JDK 1.6.0,這是一個構建命令
javac -cp $ANDROID_SDK_ROOT/platforms/android-9/android.jar TestAndroid.java
dx --dex --output=test.dex TestAndroid.class
此命令在Android上的colsole上運行測試應用程序
dalvikvm -cp test.dex TestAndroid
started
connecting
java.lang.UnsatisfiedLinkError: Native method not found: android.net.LocalSocketImpl.connectLocal:(Ljava/io/FileDescriptor;Ljava/lang/String;I)V
at android.net.LocalSocketImpl.connectLocal(Native Method)
at android.net.LocalSocketImpl.connect(LocalSocketImpl.java:287)
at android.net.LocalSocket.connect(LocalSocket.java:130)
at TestAndroid.run(TestAndroid.java:17)
at TestAndroid.main(TestAndroid.java:24)
at dalvik.system.NativeStart.main(Native Method)
我的代碼有什麼問題?我認爲android.net.LocalSocket在任何Android系統上都可用。
可能重複?不確定是否投了近距離投票... http://stackoverflow.com/questions/8885269/dalvikvm-with-input –