ndk5 exception crash with third-party library

by wasabee18 » Thu, 12 May 2011 09:01:05 GMT

Sponsored Links
 i everyone, that's my first post, please be nice :)
My problem is as follows:

I have 2 library, namely lib1 and lib2 compiled with standalone
Both libs need to use stl and exception.
I am using ndkr5, and i have problem with exception !

According to the doc in ndk (document android-ndk-r5b/docs/CPLUSPLUS-
SUPPORT.html), it is mentioned that :


IF YOU NEED THESE, PLEASE USE "gnustl_static".

so in my Application.mk, I have added:
APP_STL := gnustl_static

==================== my test with one single lib (promising)
I tested as follows:
1) Test 1 :
if i use try/catch within jni, it works with gnustl_static, but it
works as well for stlport_static. i assume it works for stlport_shared
as well
try {
throw 1
} catch (in e) {
LOHI("catch int %d", e); // OK

2) Test 2 :
if i use try/catch within my external lib, say in lib1, then it works
with gnustl_static, but it works as well for stlport_static. i assume
it works for stlport_shared as well.
try {
throw 1
} catch (in e) {
LOHI("catch int %d", e); // OK

3) Test 3:
if i throw the exception from the external lib and try to catch it
withing the jni code, then the app crashes if i use gnustl_static.
void func()
throw 1;
and in jni:
func(); // CRASH
} catch (int e) {
LOHI("catch int %d", e);

I have figured that if i use stlport_static instead of gnustl_static,
then it works! This is contradictory to what documentation says ... ??
Can someone share their experience ?

Anyway, my first tests finished, I have tried with 2 libs instead of a
single one... and the problems started.

=========================== end my test with one single lib

=================my external libs compiled with standalone toolchain
my 2 external libs are as follows:
lib1 has just one file lib1.c containing one function:
void lib1_func1(int *i)
throw 11;
According to doc android-ndk-r5b/docs/STANDALONE-TOOLCHAIN.html, it is
mentioned that:
The toolchain binaries *do* support C++ exceptions and RTTI by
They are enabled by default, so use -fno-exceptions and -fno-rtti if
want to disable them when building sources with them (e.g. to generate
smaller machine code).

NOTE: You will need to explicitely link with libsupc++ if you use
features. To do this, use -lsupc++ when linking binaries, as in:

arm-linux-androideabi-g++ .... -lsupc++


so i compile and link against lsupc++ as:
arm-linux-androideabi-g++ -mthumb -O2 -g -Wall -fpic -c lib1.c -o
arm-linux-androideabi-g++ -shared -Wl,-soname,liblib1.so lib1.o -lsupc
++ -o liblib1.so

lib2 has just one file lib2.c containing one function:
void lib2_func1(int *i)
throw 21;
i compile it as (linking against libsupc++):
arm-linux-androideabi-g++ -mthumb -O2 -g -Wall -fpic -c lib2.c -o
arm-linux-androideabi-g++ -shared -Wl,-soname,liblib2.so lib2.o -lsupc
++ -o liblib2.so

=================== end external lib

===================== Android.mk

Re: ndk5 exception crash with third-party library

by Marcin Orlowski » Thu, 12 May 2011 17:01:31 GMT


I beliee your problem shall be discussed on NDK list, not here (SDK).

Marcin Orlowski

*Tray Agenda < http://bit.ly/trayagenda> ;* - keep you daily schedule handy...
*Date In Tray* < http://bit.ly/dateintraypro> ; - current date at glance...
WebnetMobile on *Facebook < http://webnetmobile.com/fb/> ;* and
*Twitter< http://webnetmobile.com/twitter/> ;


Sponsored Links

Re: ndk5 exception crash with third-party library

by wasabee18 » Fri, 20 May 2011 17:24:28 GMT

 sorry. I intended to post it on ndk list. my mistake.
I have re-posted to ndk list.



Other Threads

1. LG GW 620

salam kenal...
aku punya lg gw 620 android 1.5 ada yang tau cara upgrade ke eclair (2.1)?

"Indonesian Android Community [id-android]" 

2. Persisting Images - Design Query

Hi guys,
I'm new enough to Android development and am still getting to grips
with the framework. I'm building a simple application that will
display some products where each product will have a name, description
and an image.

I'm using SQLite to persist the product data and have found that
pretty straight forward so far. My question is around design and
finding the best practice to solve my problem.

My question is as follows...

Where should I store the images (.png files) that are shipped with the

Given my basic knowledge I see a couple of options here
1. Store them in the res/drawable folder and access them as standard
resources e.g. R.drawable.image_name
2. Store them in the res/asset folder and access them using an
InputStream. This way I could store a URI in the database for each
image pointing to the file in the asset directory.

These approaches are fine if the data remains static, however we want
to add functionality where we will download new product data to the
device from the web.
When we download this data we can persist the name and description
part in the database (no problems here) but I'm not sure what to do
with the images. We cannot add these new images to the asset directory
with the existing images as the asset directory cannot be written to
at runtime. As far as I am concerned I have two options here

1. Use the MEDIA content provider to persist the image on the device
internal data store and store the image URI in the database to
identify the path to an image.
2. Create a folder on the file system and write my new image files to
this folder. Then store the file path in the product database to
identify an image (Not 100%
sure this is possible, can someone please confirm)

The problem with both these approaches is that there is an
inconsistency between how my initial product images are stored and how
the downloaded image updates are stored. This seems like poor design,
to have your initial images in one place (res/asset) and your
downloaded image updates persisted using the MEDIA content provder.

I need advice on how best to approach this in terms of good clean
design and best practice. I dont need specific code examples as I can
figure out the implmentation myself once I've discovered what approach
to take.

Apologies for the long post but I've been looking at this for a few
days now and have been doing quite a bit of head scratching. I'd like
to start my Andorid development off using best practices so I was
hoping some of the more experienced guys could assist.



3. Android ANT build

4. change coodinate syste

5. How to see all the applicat ions in the Google Marketé”›

6. scroll view and TableLayout

7. Option Menu Customization