MobAppDev: Android Native Development Kit
Upcoming SlideShare
Loading in...5
×
 

MobAppDev: Android Native Development Kit

on

  • 582 views

 

Statistics

Views

Total Views
582
Slideshare-icon Views on SlideShare
414
Embed Views
168

Actions

Likes
0
Downloads
2
Comments
0

39 Embeds 168

http://vkedco.blogspot.com 65
http://vkedco.blogspot.in 17
http://www.vkedco.blogspot.com 15
http://vkedco.blogspot.dk 7
http://www.vkedco.blogspot.in 4
http://vkedco.blogspot.de 4
http://vkedco.blogspot.sk 4
http://vkedco.blogspot.mx 3
http://www.vkedco.blogspot.com.br 3
http://reader.aol.com 3
http://vkedco.blogspot.pt 2
http://vkedco.blogspot.com.es 2
http://vkedco.blogspot.co.il 2
http://vkedco.blogspot.kr 2
http://vkedco.blogspot.com.tr 2
http://www.blogger.com 2
http://vkedco.blogspot.ru 2
http://www.vkedco.blogspot.kr 2
http://www.vkedco.blogspot.ro 2
http://www.vkedco.blogspot.de 2
http://www.vkedco.blogspot.com.es 2
http://www.vkedco.blogspot.fr 2
http://www.vkedco.blogspot.com.tr 2
http://vkedco.blogspot.fr 2
http://vkedco.blogspot.sg 1
http://vkedco.blogspot.ca 1
http://vkedco.blogspot.com.au 1
http://vkedco.blogspot.nl 1
http://vkedco.blogspot.cz 1
http://www.vkedco.blogspot.nl 1
http://www.vkedco.blogspot.hk 1
http://vkedco.blogspot.no 1
http://vkedco.blogspot.ae 1
http://www.vkedco.blogspot.it 1
http://vkedco.blogspot.it 1
http://www.vkedco.blogspot.ca 1
http://www.vkedco.blogspot.co.il 1
http://vkedco.blogspot.ie 1
http://vkedco.blogspot.com.br 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    MobAppDev: Android Native Development Kit MobAppDev: Android Native Development Kit Presentation Transcript

    • Android NDK Vladimir Kulyukin www.vkedco.blogspot.com
    • Outline ● Android Native Development Steps ● Sample NDK Application
    • Android NDK Development ● If you want efficiency in your code, you may want to integrate C/C++ into your projects ● On Windows, install Cygwin for C/C++ compilation ● Develop C/C++ code in your favorite IDE/Editor ● Create jni folder in your Eclipse project and place there your C/C++ source code in there, plus the two files: Android.mk and Application.mk
    • Android NDK Development ● Edit the value of LOCAL_SRC_FILES in Android.mk by listing all your .cpp files ● On Cygwin command line go into your project directory ● In your project directory, call <NDK-path>/ndk-build ● Debug, as necessary, ● Run the application
    • Problem Develop an application whose main activity that generates an array of 5 random numbers and calls a C function that increments each number by 1. The main activity displays the original and modified array in a TextView.
    • Sample Screenshot & Project Structure Source Links 1. CppFunctionsJNI.java 2. NDKIncrementArrayAct.java 3. Android.mk 4. Application.mk 5. NDKSource.cpp 6. main.xml 7. strings.xml 8. AndroidManifest.xml
    • Declaration of Native C Function in Java public class CppFunctionsJNI { static { System.loadLibrary("processJNI"); } // pass in an array of ints of size size and increment // each element by 1. public static native void incrementNumbers(int[] numbers, int size); }
    • Implementation of C Function JNIEXPORT void JNICALL Java_org_vkedco_mobappdev_ndk_jni_CppFunctionsJNI_incrementNumbers(JNIEnv *env, jclass jc, jintArray numArray, jint size) { jboolean isCopy; // copy flags // Java to C++ arrays: this is where the Java array is copied into a C array. jint *numbers = env->GetIntArrayElements(numArray, &isCopy); // this is where the C array is modified for (int i = 0; i < size; i++) numbers[i] = numbers[i] + 1; if (isCopy == JNI_TRUE) // Copy the contents of the buffer back into array and free the buffer env->ReleaseIntArrayElements(numArray, numbers, 0); else env->ReleaseIntArrayElements(numArray, numbers, JNI_ABORT); }
    • Calling Native C Function from Java int[] numbers = new int[SIZE]; Random random = new Random(); for (int i = 0; i < SIZE; i++) { numbers[i] = random.nextInt(1000); display.append(numbers[i] + "n"); } // This is where the native function is called CppFunctionsJNI.incrementNumbers(numbers, SIZE);
    • Reading & References ● http://developer.android.com/tools/sdk/ndk/index.html ● https://github.com/VKEDCO/NDKIncrementArray ● http://www.youtube.com/watch?v=3Twr1C4igAU