Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As for me I once made a note for myself about NDK. Here it is:</p> <pre><code>Required applicaitions: 1. Eclipse 2. CDT+Sequoyah plug-ins 3. Android ADT 4. Android NDK Configuration: 1. Install Eclipse, ADT, CDT and Sequoyah plug-ins 2. In the Eclipse -&gt; Window -&gt; Preferences -&gt; Android -&gt; Native Development put NDK location Steps: 1. Create new Android Project 2. Create Java class for working with native libraries (NativeLibrary.java) 3. In the class NativeLibrary.java define interface for native methods 4. Right click on Project -&gt; Android Tools -&gt; Add Native Support. Define name of the library. 5. Build the project 6. Go to PROJECT_HOME/bin 7. Create C header file with the command javah -jni &lt;packagename&gt;.NativeLibrary 8. Move this file to PROJECT_HOME/jni folder 9. Implement methods from the header file in the generated cpp file. Do not forget to include the moved header in this file. 10. In java classes create new object of NativeLibrary class and call its methods. 11. Build project. </code></pre> <p><strong>UPDATE: Step by step without plugins</strong></p> <p>Required applications - this is what you need to develop native applications. In my case I use Eclipse + Android ADT plugin + Android CDT plugin + Sequoyah plugin. You can install them using Eclipse - > Install new software</p> <p>Then you should download Android NDK. Also you should export PATH to it.</p> <p>For the configuration: you should define only path to your NDK in Eclipse -> Window -> Preferences -> Android -> Native Development</p> <p><strong>You are not obliged to use these plugins but it is easier to develop with them. However, Sequoyah contains errors (or it's sometimes not properly configured for my computer)</strong> </p> <p>After that you can create new Android project. Then you can create java class that defines native methods. In my case this is NativeLibrary.java. Here it is:</p> <pre><code>package com.testpack.nativetest; public class NativeLibrary { public native static int add(int a, int b); static { System.loadLibrary("nativ"); } } </code></pre> <p>After that build your Android project. After that go to your bin/classes (I don't know but before it was just bin directory) directory:</p> <pre><code>cd ~/programming/android/workspace/NativeTest/bin/classes </code></pre> <p>And run the following command:</p> <pre><code>javah -jni com.testpack.nativetest.NativeLibrary </code></pre> <p>This command should produce com_testpack_nativetest_NativeLibrary.h header in your bin/classes directory. It should look like:</p> <pre><code>/* DO NOT EDIT THIS FILE - it is machine generated */ #include &lt;jni.h&gt; /* Header for class com_testpack_nativetest_NativeLibrary */ #ifndef _Included_com_testpack_nativetest_NativeLibrary #define _Included_com_testpack_nativetest_NativeLibrary #ifdef __cplusplus extern "C" { #endif /* * Class: com_testpack_nativetest_NativeLibrary * Method: add * Signature: (II)I */ JNIEXPORT jint JNICALL Java_com_testpack_nativetest_NativeLibrary_add (JNIEnv *, jclass, jint, jint); #ifdef __cplusplus } #endif #endif </code></pre> <p>Create jni directory in your project and Run the following command. It will move this header to jni directory.</p> <pre><code>mv com_testpack_nativetest_NativeLibrary.h ../../jni </code></pre> <p>After that in jni directory create .c file. In my case it is nativ.c, copy the definition of the function from .h file and generate code:</p> <pre><code>#include "com_testpack_nativetest_NativeLibrary.h" JNIEXPORT jint JNICALL Java_com_testpack_nativetest_NativeLibrary_add (JNIEnv *env, jclass obj, jint a, jint b) { return a+b; } </code></pre> <p>Then in jni directory you should create a make file Android.mk Here it is. Simply change the source (nativ.c) and the name of your library (nativ).</p> <pre><code>LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := nativ LOCAL_SRC_FILES := nativ.c include $(BUILD_SHARED_LIBRARY) </code></pre> <p>Go to the PROJECT_HOME directory. In my case this is </p> <pre><code>cd ~/programming/android/workspace/NativeTest </code></pre> <p>and run ndk-build. That's all. After that you can test it in your activity:</p> <pre><code>package com.testpack.nativetest; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class NativeTestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Log.d("TEST:", "Result 5+4=" + NativeLibrary.add(5, 4)); } } </code></pre> <p>With plugins it is a bit easier to develop. But I think you should test it by yourself how to do this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload