With the support for MIPS architecture in the latest release of NDK8, the life of NDK developers became a bit more difficult again. We have 4 architectures to cross-compile a bunch of native libraries for: armebi, armebi-v7a, x86 and mips. I guess, this is just one more push to move towards Java code for better portability and smaller .APKs, etc.
By the way the issue with libc on x86 builds that I was posting about since NDK6 still exists.
One the native libraries that I use fails to build with the following errors:
undefined reference to `siglongjmp'
undefined reference to `sigsetjmp'
See here: http://aleksmaus.blogspot.com/2011/11/more-fun-with-android-ndk7.html
The x86 build fails with both Mac OS X and Linux NDK8.
If anybody on Android NDK team reads this, please, please, please fix it.
Showing posts with label NDK. Show all posts
Showing posts with label NDK. Show all posts
Wednesday, May 09, 2012
Friday, December 30, 2011
Missing pthread_mutex_timedlock on Android
I stumbled upon a problem today that the pthread_mutex_timedlock function definition is missing on Android, though it's declared in the pthread.h.
The first thought was to implement it as a loop with a call to pthread_mutex_trylock and some sleep until we are able to get the lock or until the timeout happens, felt a bit awkward.
I took a look a the Mono for Android source code and that's exactly what they do there (./mono/io-layer/mono-mutex.c), so go figure, looks like this solution might not be that bad after all.
Here is how it's implemented in Mono for example:
The first thought was to implement it as a loop with a call to pthread_mutex_trylock and some sleep until we are able to get the lock or until the timeout happens, felt a bit awkward.
I took a look a the Mono for Android source code and that's exactly what they do there (./mono/io-layer/mono-mutex.c), so go figure, looks like this solution might not be that bad after all.
Here is how it's implemented in Mono for example:
int
pthread_mutex_timedlock (pthread_mutex_t *mutex, CONST_NEEDED struct timespec *timeout)
{
struct timeval timenow;
struct timespec sleepytime;
int retcode;
/* This is just to avoid a completely busy wait */
sleepytime.tv_sec = 0;
sleepytime.tv_nsec = 10000000; /* 10ms */
while ((retcode = pthread_mutex_trylock (mutex)) == EBUSY) {
gettimeofday (&timenow, NULL);
if (timenow.tv_sec >= timeout->tv_sec &&
(timenow.tv_usec * 1000) >= timeout->tv_nsec) {
return ETIMEDOUT;
}
nanosleep (&sleepytime, NULL);
}
return retcode;
}
Friday, December 23, 2011
How to setup Eclipse for debugging with Android NDK
Just wanted to bookmark couple of useful links on how to setup Eclipse IDE for debugging with NDK. Sometimes it might be more convenient than doing ndk-gdb from terminal, that I still didn't quite get used to yet. It took a bit of time and few tries to get things going. I had some problems with symbols loading and matching, and finally succeeded. Anyways if stuck check comments to these articles.
- Setup your project to be a mixed Java, C, and C++ project:
- Setup your project to enable debugging:
Friday, December 02, 2011
Android NDK logging
Just wanted to share the snipped that often used in the different Android native projects.
The following are some useful macros for logging with NDK.
#include<android/log.h>
#define LOGD(LOG_TAG, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGV(LOG_TAG, ...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
#define LOGE(LOG_TAG, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
You can define more as needed just take a look at the android/log.h header file for all available priority values.
Then I would usually define log TAG:
#define LOG_TAG "MyModule"
and use the macros like this:
LOGD(LOG_TAG, "my val: %s", val);
fopen with native library on Android
If you develop an Android application with some native C/C++ layer (NDK) and
try to open the file from it by doing FILE *pFile = fopen ("myfile.txt" ,"w");
the fopen call will fail.
The reason is that the current working directory for you application is the root of file system '/' and naturally your application doesn't have access to it.
In order to fix this problem you have to pass the full path for the file to fopen call.
One way to do this is to pass the base path to your application data folder where your application has read/write permissions. For example you can use the Context API getFilesDir().getAbsolutePath()
and pass the result to the native function call.
This particular API resolves currently into something like: "/data/data/[app package]/files/ "
In your native code then the fopen call should succeed with
FILE *pFile = fopen ("/data/data/[app package]/files/ myfile.txt" ,"w");
Hope this was helpful.
Thursday, November 17, 2011
More fun with Android NDK7
I tried to compile cURL library Android NDK7 for x86 architecture and it looks like though the bug was reported in NDK6b: http://code.google.com/p/android/issues/detail?id=19851, the libc is still missing few functions sigsetjmp and siglongjmp.
The easiest solution for me was to get the libc from the latest ICS source tree (built for x86 arch).
The easiest solution for me was to get the libc from the latest ICS source tree (built for x86 arch).
Looking forward to get this fixed in NDK8, hopefully before Christmas.
Subscribe to:
Posts (Atom)
