Issue loading native libraries (i.e. System.load()/dlopen) on my Nexus One after FRG83 System update

168 views
Skip to first unread message

Piyush Khanna

unread,
Nov 17, 2010, 1:23:09 AM11/17/10
to android-ndk
Hi,

I am an Android app developer, and I have purchased a Nexus One device
which I use to continuously test my developed Android applications.

Background:
-----------------
One of the applications I developed uses a native shared library (e.g.
myNativeLib.so). Only my application loads & uses this native library.
I had developed this app before Android NDK came out. I pack my native
library into my apk's 'assets' folder, and during my application start-
up, I extract this native library from my package's assets folder to
my app private directory (i.e. <assets> -> /data/data/<myappprocess>/
myNativeLib.so). Then I use System.load() API in my application to
dynamically load this native library.

Problem:
------------
This application was developed during Android 1.5 (i.e. cupcake) days
{I didn't have the Nexus One then}. The above procedure has been
working without any problems right from Android 1.5 to Android 2.2
(i.e. Froyo). I have also tested the same on my Nexus One for Android
2.1 (i.e. Eclair) and Android 2.2.

The problem began the moment I recently upgraded my Nexus One to
Android 2.2.1 via the FRG83 system update. Now, whenever I try to load
my native library, I get the following error:

D/dalvikvm( 3653): Trying to load lib /data/data/<myappprocess>/
<mynativelib>.so <some address>
I/dalvikvm( 3653): Unable to dlopen(/data/data/<myappprocess>/
<mynativelib>.so): Cannot load library: link_image[1995]: failed to
link <mynativelib>.so

What I have Tried:
--------------------------
1. I tried my application using Android 2.2 SDK (emulator)...it works,
no issues.
2. I checked out the latest froyo & android2.2.1 source code from
Android open-source, built & tested my application
+ native lib using the latest froyo source...it built & ran, no
issues. This should've taken care of any changes in the
native code dependencies between Android 2.2 & Android 2.2.1
3. I even checked Android 2.2.1 source code for dalvik (java System &
Runtime classes) + bionic (linker & dlopen
sources) between Android 2.2 & Android 2.2.1 (using source checked
out from Android open-source), but couldn't
find anything consequential
4. I am unable to return my Nexus One to Android 2.2 :(

I'm now confused...is the open-sourced-code for Android 2.2.1
different from what's available on Nexus One? What can I do to make my
application work on Nexus One?



---------------------------------------
---------------------------------------
Device: Nexus One
Carrier: Airtel
Country / Language: India/en
OS / build number (if applicable): Android 2.2.1 / FRG83
---------------------------------------

alan

unread,
Nov 18, 2010, 4:22:13 AM11/18/10
to android-ndk
If you don't build using the ndk there is no guarantee that your app
will work on future devices. The solution would be to build using the
ndk. You are probably unknowingly calling some unsupported function
which has been removed or changed in 2.2.1

Piyush Khanna

unread,
Nov 19, 2010, 2:19:32 AM11/19/10
to android-ndk
Thanks for the response, Alan :)

I understand that I should ideally be using NDK. However, as I said,
the setup is from pre-NDK times, and I'd have to restructure the code
completely for NDK. Also, I'm not sure NDK provides all shared
libraries which I need.

Having said that, I compiled my native binary using the Android 2.2.1
source-code, and got no compilation/linking errors. I was also able to
load my native library without any issues on the Android 2.2.1
emulator - how so?
> > Android 2.2.1 via theFRG83system update. Now, whenever I try to load

Tim Mensch

unread,
Nov 19, 2010, 11:29:29 AM11/19/10
to andro...@googlegroups.com
On 11/19/2010 12:19 AM, Piyush Khanna wrote:
> I understand that I should ideally be using NDK. However, as I said,
> the setup is from pre-NDK times, and I'd have to restructure the code
> completely for NDK. Also, I'm not sure NDK provides all shared
> libraries which I need.
>
> Having said that, I compiled my native binary using the Android 2.2.1
> source-code, and got no compilation/linking errors. I was also able to
> load my native library without any issues on the Android 2.2.1
> emulator - how so?
If you're linking against Android shared libraries, then that's likely
your problem: There's no guarantee that a shared library will be the
same as the stock 2.2.1 library on any particular phone, or even that it
will have the same name on the phone. Or maybe there are new security
restrictions that restrict what code can be executed in 2.2.1 that are
disabled in the "rooted" emulator?

In any event, this is the NDK list, for discussing the writing of
applications for the NDK; I'm sure people on this list will be glad to
help you convert your pre-NDK project to work on the NDK, but until you
do, your question isn't an NDK question. And it seems like a good time
to restructure your code to use the NDK, so welcome to the list. ;)

If you want an answer as to how to do things without the NDK, then you
might try one of the other lists (android-porting? not sure) or Stack
Overflow.

Tim

Reply all
Reply to author
Forward
0 new messages