对于采用Android NDK提供帮助 [英] provide help for using Android NDK
本文介绍了对于采用Android NDK提供帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的项目使用Android NDK。在Android NDK所以我的问题是,如何整合和执行的默认实例项目HELLO-JNI?请提供我一步踩在上面的解决方案...我不知道什么...
解决方案
1。首先创建的Android项目
2.然后在名称JNI项目创建文件夹(不使用其他名称)3.创建文件,用Android.mk(单击鼠标右键在JNI的文件夹 - >新建 - >文件 - > Android.mk)
//编码到构建路径和访问
LOCAL_PATH:= $(叫我-DIR)//这是常见
包括$(CLEAR_VARS)//这是common`enter code here`
LOCAL_MODULE:= myCFile // myCFile是乌尔自己的模块名称
将在活动中调用)
LOCAL_SRC_FILES:= my.c //我们的C文件应该怎样在C中给出
档案建立包括$(BUILD_SHARED_LIBRARY)
4.创建C语言文件中像以上乌尔自己的名字扩展名为.C(此文件将是
在LOCAL_SRC_FILES使用)
C语言文件看起来就像这样:
注意 :
//你的包名com.JniMyDemo然后你的活动文件,然后对C文件中的函数名
所以,我用jint(返回值)
(JAVA)的绝
(com_JniDemo)的包名(com.JniDemo)被指定我们不可能使用。对于包,以便
我们把强调对C文件)
(JniMyDemoActivity)是我班前两个实际参数的重要一人是我们自己的函数变量//包括两个头文件string.h中,jni.h
的#includestring.h中
的#includejni.hjint Java_com_JniMyDemo_JniMyDemoActivity_add(JNIEnv的* ENV,jobject jobj,jint N1,N2 jint)
{
jint A,B,C;
A = N1;
B = N2;
返回(A + B);
}5.然后调用C文件筛选//活动是这样的公共类JniMyDemoActivity延伸活动{
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
TextView的TXT =新的TextView(本);
txt.setText(+添加(100,100));
的setContentView(TXT);
} 私人本地加INT(INT I,诠释J,INT K);
静止
{
的System.loadLibrary(myCFile);
}
}6.然后由编译C文件
启动终端(CMD提示符)键入像(CD项目路径)项目路径并输入
然后键入(NDK位置/ NDK的构建),它会自动编译和放大器;乌尔JNI文件夹
7.如果它成功意味着启动Actvity它将显示相加的结果
I want to use android NDK in my project. So my question is, how to integrate and execute default sample project of hello-jni from android NDK ? Please provide me step by step solution on it ... I don't know anything about it...
解决方案
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
这篇关于对于采用Android NDK提供帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文