简体   繁体   English

Android和Java的JNI

[英]Android and Java's JNI

I'm starting to learn java's JNI to use with an android device. 我开始学习java的JNI与android设备一起使用。

As I read somewhere, you must have some "glue" for the C++ part in order to be loaded through JNI. 当我在某处读到时,你必须为C ++部分添加一些“胶水”才能通过JNI加载。

My question is: Is it posible to have a run() function in C with the glue for JNI having that running the real app and having java only for the entry point? 我的问题是:在C中使用run()函数是否可行,JNI的粘合剂是运行真实应用程序并且只有入口点的java? Because I don't know if when invoking that run() function through JNI it may cause problems if that function calls another functions and so on. 因为我不知道当通过JNI调用run()函数时,如果该函数调用另一个函数等,它可能会导致问题。 Thanks for the tip! 谢谢你的提示!

EDIT: I want to code in C++ using ndk and trying to avoid coding in java. 编辑:我想使用ndk在C ++中编码,并试图避免在java中编码。 thus, I wanted to know if a) if I can compile and run in native with ndk or b) if i can use java only to invoke my app, example: calling woth jni something like app->run() and let it do all stuff instead of java. 因此,我想知道是否a)如果我可以使用ndk编译和运行本机或b)如果我只能使用java来调用我的应用程序,例如:调用woth jni类似app-> run()并让它做所有东西而不是java。 then, java will act only as an entry point. 那么,java将只作为一个入口点。

我在以下文章中逐步介绍了如何: 如何使用android创建dll如果你不理解某些东西,你可以阅读它并提出问题。

If you want to develop for Android in C/C++ (no Java) AND you target newer devices (Gingerbread, android-9 app platform onwards) consider using NativeActivity. 如果你想用C / C ++(无Java)开发Android 你可以考虑使用NativeActivity来定位更新的设备(Gingerbread,android-9 app平台)。

See http://developer.android.com/reference/android/app/NativeActivity.html and folder inside NDK package $NDK/docs/NATIVE-ACTIVITY.HTML together with the sample code $NDK/samples/native-activity . 请参阅NDK包$NDK/docs/NATIVE-ACTIVITY.HTML http://developer.android.com/reference/android/app/NativeActivity.html和文件夹以及示例代码$NDK/samples/native-activity

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM