I try to import jna.jar into my project since JNA is a very useful tool to call Native library which is base on JNI.
OS: Windows 10
IDE: Android Studio 1.5.1
JDK: 1.8.0_73
NDK: r10e
What I have done
(AS = Android Studio)
Create a new project by AS with API18.
Download jna.jar from their GitHub.
https://github.com/java-native-access/jna
- copy jna.jar into project folder.
JNATestapplibsjna.jar
- In AS, right-click on the icon of jna.jar, choose Add as Library
- Wait for few seconds, check the File->Project Structure->app->Dependencies. We do have the jna.jar. (Same as appuild.gradle)
build gradle
- Implement JAVA code about JNA in MainActivity.java
- Run app on real device Sony Z3 (arm)
- Crash by
CLibrary.Instance.printf("Hello, JNA");
Error Message on Android Monitor
E/AndroidRuntime: FATAL EXCEPTION: main
Process: i3d.jnatest, PID: 1068
java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-arm/libjnidispatch.so) not found in resource path (.)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:866)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:826)
at com.sun.jna.Native.<clinit>(Native.java:140)
..
... so on
Java code
package i3d.jnatest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CLibrary.Instance.printf("Hello, JNA");
}
public interface CLibrary extends Library
{
CLibrary Instance = (CLibrary) Native.loadLibrary("msvcrt", CLibrary.class);
void printf(String format, Object... args);
}
}
Question
According to error message, I miss /android-arm/libjnidispatch.so
in runtime.
Did I put the wrong place for jna.jar?
How should I get and use /android-arm/libjnidispatch.so
?
I am a newbie about Android Studio, so maybe misunderstanding something key-point.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…