Sunteți pe pagina 1din 39

All Topics Find tutorials, courses, and more...

Code Categories Learning Guides

ANDROID SDK

Advanced Android:
Getting Started with the
NDK
by Shane Conder & Lauren Darcey 11 Aug 2010 67 Comments

5 1 2

Learn how to install the Android NDK and begin using it. By the end of this tutorial,
you will have created your own project that makes a simple call from Java code to
native C code.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Prerequisite Experience
Before we get started, we need to take a moment here to discuss the level of this
tutorial. Its flagged as advanced. The reason for this is that we, the authors, are
going to assume that you would agree with the following statements:

1. You are experienced with Java and C.


2. You are comfortable using the command line.
3. You know how to figure out what version of Cygwin, awk, and other tools you
have.
4. You are comfortable with Android Development.
5. You have a working Android development environment (as if this writing, the
authors are using Android 2.2)
6. You use Eclipse or can translate Eclipse instructions to your own IDE with
ease.

If you arent comfortable with these, youre welcome to read this tutorial, of course,
but you may have difficulties at certain steps that would be resolved by being
comfortable with the above. That said, using the NDK is still a process that is prone
to problems and issues even if you consider yourself a mobile development
veteran. Be aware that you may have to do some troubleshooting of your own
before you get everything working smoothly on your development system.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
The complete sample project for this tutorial can be downloaded open source code.

A Note About When to Use NDK


So, if youre reading this tutorial, you may already be considering the NDK for your
Android projects. However, wed like to take a moment to talk about why the NDK is
important, when it should be used, andjust as importantly, when it should not be
used.

Generally speaking, you only need to use the NDK if your application is truly
processor bound. That is, you have algorithms that are using all of the processor
within the DalvikVM and would benefit from running natively. Also, dont forget that
in Android 2.2, a JIT compiler will improve the performance of such code as well.

Another reason to use the NDK is for ease of porting. If youve got loads of C code
for your existing application, using the NDK could speed up your projects
development process as well as help keep changes synchronized between your
Android and non-Android projects. This can be particularly true of OpenGL ES
applications written for other platforms.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Dont assume youll increase your applications performance just because youre
using native code. The Java<->Native C exchanges add some overhead, so its
only really worthwhile if youve got some intensive processing to do.

Step 0: Downloading the Tools


Alright, lets get started. You need to download the NDK. Well do this first, as while
its downloading you can check to make sure you have the right versions of the rest
of the tools you need.

Download the NDK for your operating system from the Android site.

Now, check the versions of your tools against these:

1. If on Windows, Cygwin 1.7 or later


2. Update awk to the most recent version (We're using 20070501)
3. GNU Make 3.81 or later (We're using 3.81)

If any of these versions are too old, please update them before continuing.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Step 1: Installing the NDK
Now that the NDK is downloaded (it is, right?), you need to unzip it. Do so and
place it in an appropriate directory. We put ours in the same directory that we put
the Android SDK. Remember where you put it.
At this point, you may want to add the NDK tools to your path. If youre on Mac or
Linux, you can do this with your native path setting. If youre on Windows using
Cygwin, you need to configure the Cygwin path setting.

Step 2: Creating the Project


Create a regular Android project. To avoid problems later, your project must reside
in a path that contains no spaces. Our project has a package name of
com.mamlambo.sample.ndk1 with a default Activity name of
AndroidNDK1SampleActivity youll see these appear again soon.

At the top level of this project, create a directory called jni this is where youll put
your native code. If youre familiar with JNI, the Android NDK is heavily based on
JNI concepts it is, essentially, JNI with a limited set of headers for C compilation.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Step 3: Adding Some C Code
Now, within the jni folder, create a file called native.c. Place the following C code in
this file to start; well add another function later:

#include <jni.h>
#include <string.h>
#include <android/log.h>

#define DEBUG_TAG "NDK_AndroidNDK1SampleActivity"

void Java_com_mamlambo_sample_ndk1_AndroidNDK1SampleActivity_helloLog(JNIEnv
{
jboolean isCopy;
const char * szLogThis = (*env)->GetStringUTFChars(env, logThis, &isCopy)

__android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", szLogTh

(*env)->ReleaseStringUTFChars(env, logThis, szLogThis);


}

This function is actually fairly straightforward. It takes in a Java object String

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
parameter, converts it in to a C-string, and then writes it out to LogCat.

The name of the function, though, is important. It follows the specific pattern of
Java, followed by the package name, followed by the class name, followed by the
method name, as defined from Java. Every piece is separated by an underscore
instead of a dot.

The first two parameters of the function are critical, too. The first parameter is the
JNI environment, frequently used with helper functions. The second parameter is the
Java object that this function is a part of.

Step 4: Calling Native From Java


Now that you have written the native code, lets switch back over to Java. In the
default Activity, create a button and add a button handler however you want. From
within your button handler, make the call to helloLog:

helloLog("This will log to LogCat via the native call.");

Then you have to add the function declaration on the Java side. Add the following
declaration to your Activity class:

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
private native void helloLog(String logThis);

This tells the compilation and linking system that the implementation for this method
will be from the native code.

Finally, you need to load the library that the native code will ultimately compile to.
Add the following static initializer to the Activity class to load the library by name
(the library name itself is up to you, and will be referenced again in the next step):

static {
System.loadLibrary("ndk1");
}

Step 5: Adding the Native Code Make File


Within the jni folder, you now need to add the makefile that will be used during
compilation. This file must be named Android.mk and if you named your file
native.c and your library ndk1, then the Android.mk contents will look like this:

LOCAL_PATH := $(call my-dir)

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
include $(CLEAR_VARS)

LOCAL_LDLIBS := -llog

LOCAL_MODULE := ndk1
LOCAL_SRC_FILES := native.c

include $(BUILD_SHARED_LIBRARY)

Step 6: Compiling the Native Code


Now that your native code is written and your make file is in place, its time to
compile the native code. From the command line (Windows users, youll want to do
this within Cygwin), youll need to run the ndk-build command from the root directory
of your project. The ndk-build tool is found within the NDK tools directory. We find it
easiest to add this tool to our path.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
On subsequent compiles, you can make sure everything is recompiled if you use
the ndk-build clean command.

Step 7: Running the Code


open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Now youre all set to run the code. Load the project in to your favorite emulator or
handset, watch LogCat, and push the button.

One of two things may have happened. First, it may have worked. If so,
congratulations! But you might want to read on, anyway. You probably got an error
to LogCat saying something like, Could not execute method of activity. This is fine.
It just means you missed a step. This is easy to do in Eclipse. Usually, Eclipse is
configured to recompile automatically. What it doesnt do is recompile and relink
automatically if it doesnt know anything has changed. And, in this case, what
Eclipse doesnt know is that you compiled the native code. So, force Eclipse to
recompile by cleaning the project (Project->Clean from the Eclipse toolbar).

Step 8: Adding Another Native Function


This next function will demonstrate the ability to not only return values, but to return
an object, such as a String. Add the following function to native.c:

jstring Java_com_mamlambo_sample_ndk1_AndroidNDK1SampleActivity_getString(JNI
{
char *szFormat = "The sum of the two numbers is: %i";

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
char *szResult;

// add the two values


jlong sum = value1+value2;

// malloc room for the resulting string


szResult = malloc(sizeof(szFormat) + 20);

// standard sprintf
sprintf(szResult, szFormat, sum);

// get an object string


jstring result = (*env)->NewStringUTF(env, szResult);

// cleanup
free(szResult);

return result;
}

For this to compile, youll want to add an include statement as well for stdio.h. And,
to correspond to this new native function, add the following declaration in your
Activity Java class:
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
private native String getString(int value1, int value2);

You can now wire up the functionality however you like. We used the following two
calls and outputs:

String result = getString(5,2);


Log.v(DEBUG_TAG, "Result: "+result);
result = getString(105, 1232);
Log.v(DEBUG_TAG, "Result2: "+result);

Back to the C function, youll note that we did a couple things. First, we create need
a buffer to write to for the sprintf() call using the malloc() function. This is
reasonable so long as you dont forget to free the results when youre done using
the free() function. Then, to pass the result back, you can use a JNI helper function
called NewStringUTF(). This function basically it takes the C string and makes a
new Java object out of it. This new String object can then be returned as the result
and youll be able to use it as a regular Java String object from the Java class.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Instruction Sets, Compatibility, Etc.
The Android NDK requires Android SDK 1.5 or later. In later versions of the NDK,
new headers have been made available for expanded access to certain APIsin
particular, OpenGL ES libraries.

However, thats not the compatibility were talking about. This is native code,
compiled to the processor architecture in use. So, one question you might be asking
yourself is what processor architectures are supported? In the current NDK (as of
this writing) only the ARMv5TE and ARMv7-A instruction sets are supported. By
default, the target is set to ARMv5TE, which will work on all Android devices with
ARM chips.

There are plans for further instruction sets (x86 has been mentioned). This has an
interesting implication: an NDK solution will not work on all devices. For instance,
there are Android tablets out there that use the Intel Atom processor, which has an
x86 instruction set.

So how does the NDK work on the emulator? The emulator is running a true virtual
machine, including full processor emulation. And yes, that means when running
Java within the emulator youre running a VM inside a VM.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Conclusion
How did you do? Did you get Android NDK installed and ultimately make a
functional, running application that uses native C code as part of it? We hope so.
There are many potential gotchas! along the way but in some cases, it can be
worth the effort. As always, wed love to hear your feedback.

Advertisement

About the Authors


open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Mobile developers Lauren Darcey and Shane Conder have coauthored several
books on Android development: an in-depth programming book entitled Android
Wireless Application Development and Sams TeachYourself Android Application
Development in 24 Hours. When not writing, they spend their time developing
mobile software at their company and providing consulting services. They can be
reached at via email to androidwirelessdev+mt@gmail.com, via their blog at
androidbook.blogspot.com, and on Twitter @androidwireless.

Need More Help Writing Android Apps? Check out our


Latest Books and Resources!

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Advertisement

Difficulty: Suggested Tuts+ Course


Advanced
Length:
Medium
Categories:

Android SDK Mobile Development

Translations Available:

Tuts+ tutorials are translated by our community


members. If you'd like to translate this post into
Multi-Platform Apps In C# With $15
another language, let us know! Xamarin
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
About Shane Conder & Lauren Darcey Related Tutorials
Mobile developers Lauren Darcey and Create a YouTube Client on Android
Shane Conder have coauthored numerous Code
books on Android development. Our latest
books include Sams Teach Yourself Android
Application Development in 24 Hours (3rd Edition),
Introduction to Android Application Development: Use Text-to-Speech on Android to
Android Essentials (4th Edition), and Advanced Read Out Incoming Messages
+ Expand Bio Code

Android: Tools of the Trade


Code

Jobs

Web Developer / Site Management


at Zanes Law in Phoenix, AZ, USA

Advertisement

PHP Coder with Magento Knowledge


at Yoginet Web Solutions in New Delhi,
Delhi, India
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Envato Market Item

67 Comments Mobiletuts+

Sort by Best

Join the discussion

Anand 3 years ago


Hi,
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
I want to write JNI for existing c code, I have c code and header, i
created the .so file using cygwin, I wrote the Android.mk file and
using cygwin created the shared library first it was showing
"undefined reference to function name" error, then I removed "include $
(CLEAR_VARS)" and again run the ndk-build command then shared library
was created but while running it was showing UnsatisfiedLinker
Error.my make file is
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := test
LOCAL_SRC_FILES := libtest.so

include $(PREBUILT_SHARED_LIBRARY)

#LOCAL_PATH := $(call my-dir)

see more

5 Reply Share

shr 2 years ago


If you are getting an error "make: No rule to make target" , make sure there is no space in the end of the fi
Android.mk.
5 Reply Share

mpla 4 years ago


wtf? I haven't seen any c-code like that? And they call that native? LOL
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
5 Reply Share

Zeb Kimmel a year ago


This is a great tutorial, thank you! Worked like a charm. The only change was that I had to run "ndk-build"
"jni" folder rather than from the project root directory. Again, great tutorial!
2 Reply Share

Dhaval 2 years ago


Hello guys an Update, no need of cywin for windows now. NDK directly handles that stuff
2 Reply Share

Amrut Bidri > Dhaval 2 years ago


Hi Dhaval, i need to know how does it do that. i want to know how eclipse comes that it is using nd
2 Reply Share

pournima > Amrut Bidri 2 years ago


hey, you need to add into your path i.e into environment variable set
ANDROID_NDK=~/src/android-ndk-r6b
ANDROID_SDK=~/src/android-sdk-linux
PATH=$PATH:$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-
x86/bin:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
and set path into eclipse Windows -> Preferences -> Android ->NDK
where public native void display(); the native gives an hint about using an NDK
Reply Share

amit 3 years ago


nice tutorial!
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
i am in home directory of the project and then i tried running ndk-build
it was working for me earlier but now it gives
ndk-build

Android NDK: Your APP_BUILD_SCRIPT points to an unknown file:


/Users/naveenkumar/workspace/com.gslab.zap:/Users/naveenkumar/Android/android-ndk-
r8:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/naveenkumar/Android/android-ndk-
r8:/usr/X11/bin:/usr/local/git/bin/jni/Android.mk

i got that the path is not the one given here but it has to be
/Users/naveenkumar/Documents/workspace/JniHello/jni/Android.mk
where my Android.mk is present but i dont kw how to change APP_BUILD_SCRIPT to point to this locatio

help me out thanks in advance


1 Reply Share

Michael 4 years ago


Hi,
Thanks for the tutorial.
I tried following on it but I always get the following error message :
make: *** No rule to make target `/native.c'
I have Eclipse 3.6 , latest cygwin and latest ndk package for Windows.

What am I doing wrong?


1 Reply Share

Andy > Michael 2 years ago

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Michael, I'm running into the same problem as you, any chance you have figured it out?
Reply Share

Ankita Dodia 15 days ago


Hello,

I am working as Android Developer and at present i m working on configure FFMPEG library for Android. I
Google and i found your post it is so helpful , but first i need to build FFMPEG library for my application i ha
for do that, but its not working because i m using windows 8 and cygwin so some command is not workin
cygwin, it's give me error like c compiler dose not create executable file or c compiler not found...

Please, help me... give me any hint for how to build FFMPEG for my application
Reply Share

Janshair Khan 9 months ago


Hi ,

I import your code package and tried running but got this error

Caused by: java.lang.UnsatisfiedLinkError: Native method not found:


com.mamlambo.sample.ndk1.AndroidNDK1SampleActivity.helloLog:(Ljava/lang/String;)V

I tried finding the answer on stack overflow but nothing seems to work . Any help in this regard would be h
appreciated.

Thanks
Reply Share

TTimo > Janshair Khan 8 months ago


open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
I have the same problem. Compiles fine, but native call is crashing with this error.

Janshair, try this patch: https://gist.github.com/TTimo/...

That fixed it for me. Looks like the export and calling conventions are required now.
Reply Share

Chris a year ago


Coding failure in Step 8:
malloc(sizeof(szFormat) ...
One solution would be to use strlen(szFormat) instead.

I would probably use a simpler allocation by "char szResult[100];" in order to avoid the malloc()/free() code
understand the point you are making regarding freeing any memory allocated for the parameters into (*en
>NewStringUTF().

Great tutorial otherwise, thank you.


Reply Share

Gaurav Mishra a year ago


HI, this was a very helpful tutorial, and I was able to make the NDK work following this tutorial step by step
Reply Share

Jacek a year ago


Very helpful tutorial. Thank you ! ;)
Reply Share

neeraj 2 years ago

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Sir how to call objective-c function from the android class and what to write in Android.mk
Reply Share

Joel Odom 2 years ago


This is an EXCELLENT tutorial. Got me up and running with native development very quickly.
Reply Share

Phearin 2 years ago


that tutorial works out well at my side, and i'm getting to understand more about JNI from this.
thank you...
Reply Share

JohnV 2 years ago


Hi. I got *most* of the way through the tutorial, but when I run ndk-build I get this message:
"/cygdrive/c/Users/John/workspace/android-ndk-r8c-windows/android-ndk-r8c/build/core/
Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in
./AndroidManifest.xml"

Any thoughts on why? I'm stumped. Thanks in advance, John


Reply Share

Quang vv > JohnV 2 years ago


file project.properties edit target=android-10
Reply Share

Frank Hvin 2 years ago


I've copied the EXACT same names for the files, project etc. Stil, when running your exact code, I get:

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
jni/native.c:1:17: warning: extra tokens at end of #include directive [enabled by default]
jni/native.c:2:20: warning: extra tokens at end of #include directive [enabled by default]
jni/native.c:3:25: warning: extra tokens at end of #include directive [enabled by default]
jni/native.c: In function 'Java_com_mamlambo_sample_ndk1_AndroidNDK1SampleActivity_helloLog':
jni/native.c:8:38: error: 'gt' undeclared (first use in this function)
jni/native.c:8:38: note: each undeclared identifier is reported only once for each function it appears in
jni/native.c:8:74: error: 'amp' undeclared (first use in this function)
jni/native.c:8:77: error: expected ')' before ';' token
/cygdrive/c/android-ndk-r8c/build/core/build-binary.mk:260: recipe for target `obj/local/armeabi/objs/ndk1/n
failed
make: *** [obj/local/armeabi/objs/ndk1/native.o] Error 1
jni/native.c:1:17: warning: extra tokens at end of #include directive [enabled by default]
jni/native.c:2:20: warning: extra tokens at end of #include directive [enabled by default]
jni/native.c:3:25: warning: extra tokens at end of #include directive [enabled by default]
jni/native.c: In function 'Java_com_mamlambo_sample_ndk1_AndroidNDK1SampleActivity_helloLog':
jni/native.c:8:38: error: 'gt' undeclared (first use in this function)
jni/native.c:8:38: note: each undeclared identifier is reported only once for each function it appears in
see more

Reply Share

makar 2 years ago


I cannot understand what include paths to use if I want to, for instance, use the ndk's version of string
Reply Share

Sohel 2 years ago


Nice Post.
Thanks
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Reply Share

Ian 2 years ago


But for development using cocos2dX cygwin is required.
Reply Share

putria febriana 2 years ago


c:/dev/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-
androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld.exe: BFD (GNU Binutils) 2.21 assertion fail
/usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../binutils/binutils-2.21/bfd/elf32-arm.c:101
c:/dev/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-
androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld.exe: BFD (GNU Binutils) 2.21 assertion fail
/usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../binutils/binutils-2.21/bfd/elf32-arm.c:101
Install : libnative_sample.so => libs/armeabi-v7a/libnative_sample.so
c:/dev/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-
androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld.exe: BFD (GNU Binutils) 2.21 assertion fail
/usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../binutils/binutils-2.21/bfd/elf32-arm.c:101

c:/dev/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-
androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld.exe: BFD (GNU Binutils) 2.21 assertion fail
/usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../binutils/binutils-2.21/bfd/elf32-arm.c:101
Reply Share

dhaneesh 2 years ago


Good guide but ,when I am trying to compile the native.c using ndk-build it shows:

ndk-build : commnad not found

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
what is the reason behing problem?
Reply Share

pournima > dhaneesh 2 years ago


ndk-build file is located on into android-ndk-r8e tool kit. So u need to check the path where the NDK
from your project path i.e ../android-ndk-r8e/ndk-build
or check http://stackoverflow.com/quest...
Reply Share

Andy 2 years ago


Hey guys,

I had a general question about using the NDK. Do I need to put the native code information in an Activity, o
be used in a regular class?

static {
System.loadLibrary("ndk1");
}

private native void helloLog(String logThis);

This is the code I am talking about. I would also like to make the methods static, so that every Activity I hav
access them. Do you know if this is possible?
Reply Share

pournima > Andy 2 years ago


check this out : http://marakana.com/forums/and...
Reply Share

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Jimmy 3 years ago
Hey,
In your example you say to call the native function, put the following in the default Activity. I currently have a
with multiple files written in C, and multiple Activities. Each Activity needs to call different methods from a
different C files. Is there any sort of declaration that tells the Activity where to look for the correct native me
does it just search the JNI folder on its own and find them?
Thanks,
Jimmy
Reply Share

Jim 3 years ago


Hey, I'm not stuck just yet, but have a question to ask. When you say "Add the NDK Tools to my path," wh
within the NDK folder am I added to the PATH variable? I'm not familiar with Environment Variables and no
how they work.
Reply Share

Jimmy > Jim 3 years ago


The NDK folder itself...
Reply Share

Andrew 3 years ago


Hey, I'm trying to run the ndk-build from Cygwin. I know this question is very stupid, but I cannot reach the
directory. If I do cd .., it brings me to the Cygwin home folder. I need to go back three more folders, then go
workspace. Am I doing something wrong? I feel like there needs to be a simple fix...
Reply Share

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Jimmy > Andrew 3 years ago
Change the Path variables in your bash_profile file within the cygwin/home directory
Reply Share

Aneesv 3 years ago


Is there any way to build android source into apk using php code ?
Reply Share

amit 3 years ago


NAVEEN-KUMARs-MacBook-Pro:ndkfoo naveenkumar$ ls
AndroidManifest.xml bin jni obj project.properties src
assets gen libs proguard.cfg res
NAVEEN-KUMARs-MacBook-Pro:ndkfoo naveenkumar$ /Users/naveenkumar/Downloads/android-ndk-r8/
NDK_LOG=1
HOST_OS=darwin
HOST_ARCH=x86_64
HOST_TAG=darwin-x86 (no 64-bit prebuilt binaries detected)
GNUMAKE=/Users/naveenkumar/Downloads/android-ndk-r8/prebuilt/darwin-x86/bin/make (NDK prebuilt)
Android NDK: NDK installation path auto-detected: '/Users/naveenkumar/Downloads/android-ndk-r8'
Android NDK: GNU Make version 3.81 detected
Android NDK: Host OS was auto-detected: darwin
Android NDK: Host operating system detected: darwin
Android NDK: Host CPU was auto-detected: x86
Android NDK: HOST_TAG set to darwin-x86
Android NDK: Host tools prebuilt directory: /Users/naveenkumar/Downloads/android-ndk-r8/prebuilt/darwin
Android NDK: Host 'echo' tool: echo
Android NDK: Host 'awk' tool: /Users/naveenkumar/Downloads/android-ndk-r8/prebuilt/darwin-x86/bin/awk
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
see more

Reply Share

aj_shehan 3 years ago


The android developer site tells that using NDK does not improve the application performance since it run
nayway, is this true? are there any improvements in performance when using NDK in application practica
on a blog which also provides a tutorial on a basic app that uses NDK and it said that it does improve perf
Can you please clarify this for me.

Than You
Reply Share

fangstar 3 years ago


Nice Guide.

Had a trouble with the extra spaces in the makefile but otherwise perfect.
Reply Share

Kike 3 years ago


Excellent post!!
I had some trouble building in VM (virtual box - android x86). But I resolved by adding a file "
folder with the line:

APP_ABI: = x86

Greetings (from the third world). Kike.


Reply Share

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Hwang 3 years ago
Thx from korea!

I love your posts.


Reply Share

krish 3 years ago


nice tutorials..pls send me simple login form using android native apps
Reply Share

Martin 3 years ago


Really nice guide, thank you for that!

I have however a suggestion to improvement, you could mention that it is very important not to have any n
spaces in the Android.mk

When I copied your Android.mk from the site two whitespaces was inserted after LOCAL_PATH := (call m
gave me an unfriendly error and it was hard figuring out the cause, as always uncle internet saved my day

This might however help others.

Thanks for a superb guide!


Martin.
Reply Share

Abraham 3 years ago


Awesome, thanks a lot.
Reply Share

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Kiet 3 years ago
Thank you. Your demo is short and precise. I was able to pass data from C to Java. Just missing the add
Vinay pointed out.
Kiet
Reply Share

Divye Kapoor 4 years ago


There's a bug in your native code:
You incorrectly size the buffer szResult to be of size 24/28 bytes leading to a potential buffer overflow in y
sprintf(szResult, szFormat, sum);

In the code:

// malloc room for the resulting string


szResult = malloc(sizeof(szFormat) + 20);

the size of the char array allocated to szResult is 24 bytes as sizeof(szFormat) == 4 or 8 as szFormat is
char* (which is 4 bytes on a 32 bit machine and 8 bytes on a 64 bit machine). The results would have bee
if you had initialized szFormat as char[] szFormat = "..."; where upon sizeof(szFormat) would have given
size of the format string in bytes.

Please fix.

Thanks.
Reply Share

DietCokeOfEvil 4 years ago


Great post, this really helped me get up and running.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Reply Share

immibis 4 years ago


sizeof(szFormat) should really be strlen(szFormat), since the size of the pointer is probably 4, even thoug
is much longer.
Reply Share

Abraham 4 years ago


Awesome Tutorial, thanks for sharing sir!!!
Reply Share

Charles Maxwell 4 years ago


I have built an Android application using shared libraries using the NDK. The emulator is currently running
x86 platform. However, I now need to move libraries over to an ARM processor. I also would like to use a c
compiler specific for the device's platform that also handles C++ better. Everything I've read so far is rathe

1) How do I change to a new platform?


2) How do I change to use an existing cross-compiler?
Reply Share

Load more comments

Subscribe d Add Disqus to your site Privacy

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Facebook App
Events
Reach Specific Sets of Your
Users with Facebook Mobile
App Ads.

Advertisement

18,892 Tutorials 461 Video Courses


Teaching skills to millions worldwide.

Follow Us Email Newsletters

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Get Tuts+ updates, news, surveys &
offers.

Help and Support Email Address

FAQ
Subscribe
Terms of Use
Contact Support Privacy Policy
About Tuts+
Advertise
Teach at Tuts+

Custom digital services like logo design, WordPress installation, video


production and more.
Check out Envato Studio

Build anything from social networks to file upload systems. Build faster
with pre-coded PHP scripts.
Browse PHP on CodeCanyon

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
2014 Envato Pty Ltd. Trademarks and brands are the property of their respective
owners.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com

S-ar putea să vă placă și