Producing optimised NDK code for multiple architectures?

ARM processors have 2 general instruction sets that they support: “ARM” and “Thumb”. Though there are different flavors of both, ARM instructions are 32 bits each and Thumb instructions are 16 bits. The main difference between the two is that ARM instructions have the possibility to do more in a single instruction than Thumb can. … Read more

How to get “printf” messages written in NDK application?

use __android_log_print() instead. You have to include header <android/log.h> Sample Example. __android_log_print(ANDROID_LOG_DEBUG, “LOG_TAG”, “\n this is log messge \n”); You can also use format specifier like printf – __android_log_print(ANDROID_LOG_DEBUG, “LOG_TAG”, “Need to print : %d %s”,int_var, str_var); Make sure you also link against the logging library, in your Android.mk file: LOCAL_LDLIBS := -llog Ohh.. forgot … Read more

Logging values of variables in Android native ndk

Here’s the most concise way I’ve seen: #include <android/log.h> #define LOG_TAG “someTag” #define LOGE(…) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) #define LOGW(…) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) #define LOGD(…) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) #define LOGI(…) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) … // Now you can log very simply like this: int foo = 42; LOGD( “This is a number from JNI: %d”, foo ); Also, make sure you link to the … Read more

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

If you can live with only supporting Android 4.1+, just set APP_PLATFORM := android-16 and you’ll be good to go. Behind the scenes it sets APP_PIE := true. Your binary will segfault on older SDKs. If you also need to support lower SDK levels, you’ll need to create two binaries. Some other answers I’ve seen … Read more

Android NDK: getting the backtrace

Android have no backtrace(), but unwind.h is here to serve. Symbolization is possible via dladdr(). The following code is my simple implementation of backtrace (with no demangling): #include <iostream> #include <iomanip> #include <unwind.h> #include <dlfcn.h> namespace { struct BacktraceState { void** current; void** end; }; static _Unwind_Reason_Code unwindCallback(struct _Unwind_Context* context, void* arg) { BacktraceState* state … Read more

How to fix android studios 2.3 NDK bug?

I was able to prevent this annoying message; here is what worked for me. BACKGROUND: I am not using the NDK at all, and had never installed the NDK. However, as mentioned in another answer here by xsveda, this is a Gradle bug that is documented here: https://code.google.com/p/android/issues/detail?id=228424 and so even the “NDK-innocent” may become … Read more

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

It turned out that this approach does not entirely work when compiling a debuggable library. The release library is compiled with -O2 which optimizes out some infelicities, but the debug library is done with -O0 which reveals some additional problems. Furthermore, I wasn’t too happy about having to edit the boost files. So with some … Read more

How to create an object with JNI?

Since Point is an inner class, the way to get it would be jclass cls = (*env)->FindClass(env, “com/example/ndktest/NDKTest$Point”); The $ convention for inner classes is not really clearly documented in the authoritative specs, but is entrenched in so much working code that it’s unlikely to change. Still, it would feel somewhat more robust if you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)