предоставить помощь по использованию Android NDK - PullRequest
1 голос
/ 08 июля 2011

Я хочу использовать Android NDK в моем проекте. Итак, мой вопрос, как интегрировать и выполнить пример проекта по умолчанию hello-jni из Android NDK? Пожалуйста, предоставьте мне пошаговое решение ... Я ничего об этом не знаю ...

Ответы [ 4 ]

5 голосов
/ 30 августа 2011
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
4 голосов
/ 08 июля 2011

Вот довольно хороший учебник для начинающих NDK: Начало работы с NDK .

1 голос
/ 09 июля 2012

У вас есть отличный учебник, объясняющий все, что вам нужно для использования NDK, как создавать функции и как их использовать, и за ним легко следовать.http://marakana.com/s/introduction_to_ndk,1153/index.html, извините за мой английский, а не за мой родной язык.

1 голос
/ 18 апреля 2012

Изучите это сложный способ запомнить вещи. Внутри Andaroid NDK, который вы скачали с developers.android.com, у вас будет папка docs, в которой у вас будут разные документы, в которых будет четко указано, как и когда следует использовать NDK. ОБЗОР.HTML Полностью. http://developer.android.com/sdk/ndk/index.html

Я так и сделал, когда впервые использовал NDK. И я настоятельно рекомендую только так ...

Если вы не уверены, что такое Native Code -> Это код C или C ++ или Assembly, который вы хотите использовать с приложением Android. Это называется нативным кодом, поскольку не на языке Java.

Всего наилучшего.

...