我想在我的项目中使用android NDK。所以我的问题是,如何整合并执行Android NDK的hello-jni的默认示例项目?请给我提供一步一步的解决方案...我对此一无所知......为使用Android NDK提供帮助
1
A
回答
4
这是NDK初学者的一个很好的教程:Getting Started with the NDK。
5
1. First Create Android Project
2. Then Create Folder in the Project with name jni (Dont use other name)
3. Create File With the Android.mk (Rightclick on the jni folder ->New -> File - >Android.mk)
// Coding To Build Path and Access
LOCAL_PATH :=$(call my-dir) // This is Common
include $(CLEAR_VARS) // This is common`enter code here`
LOCAL_MODULE := myCFile // myCFile is ur own Name of the module
that will be called in Activity)
LOCAL_SRC_FILES := my.c // Our C File What should be given in C
file creation
include $(BUILD_SHARED_LIBRARY)
4. Create C File like above With ur own name with the extension .c (This file will be
used in LOCAL_SRC_FILES)
C File Will Look Like this:
Note :
// Your Package name com.JniMyDemo Then Your Activity File and then the Function name for c file
So that I used jint(return value)
(Java) its must
(com_JniDemo) is Specified in Package name(com.JniDemo) we couldnt use . for package so
we put underscore for c file)
(JniMyDemoActivity) Is my class
First two arguement is Important one others are our own variable for function //
Include two header file string.h,jni.h
#include "string.h"
#include "jni.h"
jint Java_com_JniMyDemo_JniMyDemoActivity_add(JNIEnv *env,jobject jobj,jint n1,jint n2)
{
jint a,b,c;
a=n1;
b=n2;
return (a+b);
}
5. Then Call the The C File Like this
// Activity Look like this
public class JniMyDemoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView txt =new TextView(this);
txt.setText(" "+add(100,100));
setContentView(txt);
}
private native int add(int i,int j,int k);
static
{
System.loadLibrary("myCFile");
}
}
6. Then Compile the C File by
Starting Terminal (cmd prompt) Type the Project Path like (cd Project Path) and Enter
Then type the (Ndk Location/ndk-build) it will automatically compile & ur jni folder
7. If it success means Start the Actvity it will show the Result of Addition
1
了解它是记住事情的艰难方法。您从developers.android.com下载的Andaroid NDK内部,您将拥有docs文件夹,您将在其中拥有不同的文档,这些文档将清楚地告诉您应该如何以及何时使用NDK。尤其是完全通过 OVERVIEW.HTML。 http://developer.android.com/sdk/ndk/index.html
我这样做,当我第一次使用NDK。我强烈建议只有这样..
如果你感到困惑什么是本地代码 - >它是你想用于Android应用程序的C或C++或汇编代码。这被称为本地代码,因为它不是用java语言编写的。
所有最优秀的。
+0
我是NDK的新手,已经多次阅读了OVERVIEW.HTML,并且有更好的教程。阅读并不会造成伤害,但遗漏了很多细节,主要是建立它(这是他想要做的)。 – JuiCe
1
你在这里有一个很好的教程,解释你需要使用NDK,如何创建一个函数以及如何使用它们,这很容易遵循。 http://marakana.com/s/introduction_to_ndk,1153/index.html,对不起我的英文,而不是我的母语。
相关问题
- 1. Android-ndk会为NFC编程提供任何帮助吗?
- 2. 有关Android NDK的帮助
- 3. CYGWIN提供帮助
- 4. 帮助内容提供商
- 5. 无法提供帮助(exec)
- 6. QLocalServer - 为初学者提供的帮助
- 7. 为newb提供一些帮助
- 8. xsl:为每组需求提供帮助
- 9. Android(JNI/NDK)OpenGL - FPS显示帮助
- 10. 用Java程序提供帮助内容
- 11. 在MS Access中提供表单帮助
- 12. 位图索引如何提供帮助?
- 13. Java OAuth提供程序库帮助
- 14. 在VB.NET中提供帮助文档?
- 15. XSL for-each-group,如何提供帮助
- 16. 要求提供AntiContainer JSON帮助
- 17. .NET为大型应用程序提供F1帮助
- 18. 什么是为应用程序提供帮助的好方法?
- 19. 如何为我的.NET应用程序提供帮助?
- 20. NDK初学者的帮助,java.lang.UnsatisfiedLinkError
- 21. 帮助使用android ClipDrawable
- 22. 使用AsyncTask的Android帮助
- 23. Android内容提供商;帮助设计可敬的URI结构
- 24. 是否有帮助创建内容提供者的Android工具?
- 25. 需要帮助配置ffmpeg解码原始AAC用android ndk
- 26. Android NDK:为相同的abi提供库变体
- 27. 向ProcessBuilder提供提示以帮助commanline工具使用其他实用程序
- 28. 将.obj文件转换为.js的帮助,convert_obj_three.py由three.js提供
- 29. 在Qt中为模态对话框提供帮助
- 30. 如何让Eclipse为Hivemind配置文件提供更多帮助?
我已经在这里编写了一步一步的教程。 http://www.permadi.com/blog/2011/09/setting-up-android-jni-projects-in-windows-eclipse-and-sequoyah/希望它有帮助。 – 2011-09-14 07:02:53
http://stackoverflow.com/questions/1541884/android-jni-guidelines/10316693#10316693 这个链接显示了一步一步的过程来创建/构建和使用android ndk。 – Raulp