Saturday, February 8, 2014
How to call dll or so in android project?
Make a android project, you need to call an open source ocr function provides a library dll or so.
But how to call in android project?
Reply:
System.loadLibrary ("");
Reply:
+1
Reply:
Direct tune it? It should be some pre-configuration, as well as dll and so can tune it? Best to give a simple example
Reply:
You can use the native method implementation steps:
1, a statement in Java native () method, and then compile;
2 h to generate a file with javah;.
3, write a cpp file export realization native method which needs to contain a second step to produce the h file (note jni.h document which also contains the JDK belt);..
4, the third step of the c file compiled into a dynamic link library file;
5, the fourth step is to load the dynamic link library file generated in Java using System.loadLibrary () method, the native () method can be accessed in Java it.
First written document
JAVApublic class NativeExampleActivity extends Activity {
TextView textView01;
private Button btnStart;
/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
btnStart = (Button) this.findViewById (R.id.btnStart);
btnStart.setOnClickListener (clickButtonStart);
textView01 = (Button) this.findViewById (R.id.btnStart);
}
private OnClickListener clickButtonStart = new OnClickListener ()
{
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
textView01.setText ("4 +5 =" + addFunction (4, 5));
}
};
static {
try {
. Runtime.getRuntime () loadLibrary ("org_natives_example_NativeExampleActivity");
} Catch (Throwable t) {
}
}
public native int addFunction (int a, int b);
}
Then execute javah-jni org.natives.example.NativeExampleActivity,
under bin / classes directory project
'll Get a org_natives_example_NativeExampleActivity.h file in the root directory
Then write com_hode_hodeframework_modelupdate_CheckFile.c file
based on the contents of the header file
# Include "com_hode_hodeframework_modelupdate_CheckFile.h"
JNIEXPORT jint JNICALL Java_org_natives_example_NativeExampleActivity_addFunction
(JNIEnv *, jobject, jint a, jint b)
{
return (a + b);
}
C file is compiled into the ko files to the phone the next push system / lib directory. On it.
Command cl-LD org_natives_example_NativeExampleActivity.cpp, can be compiled into a lib, dll, obj file
Reply:
My mistake in javah "Error: Can not access android.app.Activity
Can not find android.app.Activity class file "
If the package inside the javah into words "Error: Can not find 'NativeExampleActivity' class files."
Reply:
And I do not understand what the library calls, if I want to use the existing a.dll (a.so can) how to call?
Reply:
There are no large cattle help answer ah?
Reply:
xxx.so first android project, then put libs / armeabi / libs built himself a following no. . .
The code then direct reference System.loadLibrary ("xxx");
Then all kinds of public native methods. . . . .
Reply:
If you do not understand, please google Android NDK compiled. . . You know how to use it. . .
Reply:
Seems to be not directly import, press the 4th floor of the way to create the so jni file, and then call in a third party so that so file reference http://www.360doc.com/content/11/0609/19/ 1861654_122741977.shtml
Reply:
Ah, thank you. I'll try ~
Reply:
I found a way, and with the JNA.
JNI is too complicated, there is always a problem when javah successfully once, then there is no on too, the principle is difficult to understand.
http://apps.hi.baidu.com/share/detail/31610125
Reply:
Looks like the landlord has a JNA share
Links how unreasonable ah?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment