Questions tagged [android-ndk]

The Android Native Development Kit (NDK) is a companion tool to the Android SDK that lets build performance-critical portions of apps in native code or port existing libraries in C/C++ to Android. It provides headers and libraries that allows to build activities, handle user input, use hardware sensors, access application resources, and more, when programming in C/C++.

Android NDK applications that include Java code and resource files and and/or source code (and sometimes code). All native code is compiled into a dynamic linked library (.so file) and then called by Java in the main program using a mechanism:

Android NDK Application

The NDK is a powerful tool for developing Android applications because it:

  • Builds performance-critical portions of your applications in native code. When using Java code, the Java-based source code needs to be interpreted into machine language using a virtual machine. In contrast, the native code is compiled and optimized into binary directly before execution. With proper use of native code, you can build high performance code in your application, such as hardware video encoding and decoding, graphics processing, and arithmetical operation.
  • Reuses legacy native code. C/C++ codes can be compiled into a dynamic library that can be called by Java code with a JNI mechanism.

More information:

Latest Version: NDK Downloads

Version History: NDK Archives

Resources:

FAQ:

Books:

13539 questions
58
votes
4 answers

How to use the boost library (including shared_ptr) with the Android NDK and STLport

This is more of an answer than a question, because I've figured it out, at least as far as cleanly compiling the library. The main issue for me was to get shared_ptr working. Ingredients: Boost v. 1.45.0 The version of STLport at…
Gamma Draconis
  • 1,166
  • 1
  • 9
  • 11
57
votes
18 answers

How to fix android studios 2.3 NDK bug?

I'm assuming it's a bug since I didn't have any problems until the new update. So I cant use the gradle console to debug my app because I have this warning - "Configuration on demand is an incubating feature. NDK is missing a "platforms"…
Ryder Thacker
  • 1,472
  • 3
  • 13
  • 33
55
votes
8 answers

Android NDK: getting the backtrace

I'm developing the native application that works with Android via the NDK. I need to call the backtrace() function when there is a crash. The problem is that there is no for the NDK. Is there any other way to get that back trace?
givi
  • 1,883
  • 4
  • 22
  • 32
55
votes
6 answers

Convert JNI types to Native types

While there is documentation regarding turning a jstring to a native string (string nativeString = env->GetStringUTFChars(jStringVariable, NULL);) I can't find an example which will convert a jboolean to a bool or a jint to an int. Can anyone…
Graeme
  • 25,714
  • 24
  • 124
  • 186
55
votes
3 answers

Running a native library on Android L. error: only position independent executables (PIE) are supported

When I run native code on Android L (Nexus 5), I get the error. error: only position independent executables (PIE) are supported. The same code is executed correctly on my Samsung Galaxy S3 (Android 4.3). Here is my Application.mk APP_PROJECT_PATH…
Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
54
votes
4 answers

Logging values of variables in Android native ndk

I set up logging with C++ in Android NDK. I can print a message to logcat like this: __android_log_write(ANDROID_LOG_INFO, "tag here", "message here"); Now let's say I have an integer called testint. How can I print the value of this…
dorien
  • 5,265
  • 10
  • 57
  • 116
54
votes
3 answers

How to get "printf" messages written in NDK application?

if i am defining such function in java file /** * Adds two integers, returning their sum */ public native int add( int v1, int v2 ); so i need to code in c file JNIEXPORT jint JNICALL Java_com_marakana_NativeLib_add (JNIEnv * env,…
Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
53
votes
17 answers

Android NDK java.lang.UnsatisfiedLinkError: findLibrary returned null

Having the above error in your Android JNI app? Read on... Up front, I'll say that I've already solved this, in my own way, but I feel something in the Android build system (perhaps regarding Eclipse) is broke, and I hope to save someone else hours…
Lee Dixon
  • 839
  • 1
  • 7
  • 8
53
votes
2 answers

Producing optimised NDK code for multiple architectures?

I have some C code for Android that does lots of low-level number crunching. I'd like to know what settings I should use (e.g. for my Android.mk and Application.mk) files so that the code produced will run on all current Android devices but also…
rbcc
  • 2,452
  • 3
  • 26
  • 28
52
votes
6 answers

Android NDK: No rule to make target

I'm trying to build a simple Android application using NDK. Here are the contents of my Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_LDLIBS := -llog LOCAL_MODULE := myNDK LOCAL_SRC_FILES := native.c include…
Ivan
52
votes
1 answer

How to use JNI bitmap operations for helping to avoid OOM when using large images?

Background most of the times, getting OOM on android is due to using too many bitmaps and/or creating large bitmaps. recently i've decided to try out JNI in order to allow avoiding OOM by storing the data itself on the JNI side. after messing…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
51
votes
4 answers

Android.mk, include all cpp files

I'm trying to build an Android project using the ndk, but I have run into some troubles. Here's the Android.mk file that works: LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := mylib LOCAL_CFLAGS := -Werror LOCAL_SRC_FILES…
gq3
  • 839
  • 1
  • 8
  • 20
51
votes
2 answers

How to match int to enum

I am receiving return value in the form of long or int from Native code in Android, which I want to convert or match with enum, for processing purpose. Is it possible ? How?
Sachchidanand
  • 1,291
  • 2
  • 18
  • 35
51
votes
4 answers

Official "Boost library" Support for Android and iOS?

This question is in continuation to Should I choose Boost Asio or Aysnc Socket threads in Android? asked, Boost libraries are intended to be widely useful, and usable across a broad range of applications, but yet there is no official support…
Rohit
  • 6,941
  • 17
  • 58
  • 102
49
votes
4 answers

ffmpeg for a android (using tutorial: "ffmpeg and Android.mk")

I am trying to compile ffmpeg for a android. I have found several posts on this theme but non of these seems to work. If tried to build ffmpeg like it is posted on [1]. Did anybody successfully compile ffmpeg using theses tutorial? I am not sure how…
Matthias
  • 491
  • 1
  • 5
  • 3