Re: NDK r8b, .so file not loading on Android 4.0 and less

918 views
Skip to first unread message

David Turner

unread,
Nov 16, 2012, 5:45:36 AM11/16/12
to andro...@googlegroups.com
One possible source of conflict is that one of your shared libraries has the same name that a system one that was already loaded in the Zygote process.
Such a library would have been removed from the system in 4.1 though, so the chances of this are pretty slim.

Can you give the names of the shared libraries in your .apk?


On Tue, Nov 13, 2012 at 9:32 PM, Thomas Hogarth <thomas....@gmail.com> wrote:
Hi All

This is my first post here, so apologies if this topic has been covered, but I've not found it myself.

I've been using the NDK for a fair few months now, and have recently been tasked with porting osgEarth to Android


Everything has gone fine so far and I have successfully run an osgEarth app on my Nexus 7 (which runs Android 4.1)

The problem arises when I try to run it on my other devices which run 4.0 or lower.

Basically it gets to the point that it tries to load the .so file, but then nothing happens, it doesn't crash either.


I checked on the file system of my Galaxy S2 and the .so file was in the location it is trying to load so I'm a little stumped.

I'm using NDK r8b which is the only difference to things I've done before, so I was wondering if there is a bug that might
be known about.

I've also attached my Android.mk file for the actual applications .so lib.

Any help would be much appreciated
Tom

PS 
Had to remove attachment to post ;(

 

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/cp77Z1VK3ykJ.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Thomas Hogarth

unread,
Nov 17, 2012, 1:45:50 PM11/17/12
to andro...@googlegroups.com
Soory for the walls of text, but here is some log output from the two devices in question, Nexus 7 works, Galaxy S2 doesn't.
You can clearly see the lib load working on Nexus 7, but not doing anything (no error even) on Galaxy S2.

Nexus 7 running 4.1

11-17 18:35:04.313: I/ActivityManager(364): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=osgearth.Example/.osgViewer u=0} from pid 23300
11-17 18:35:04.333: D/AndroidRuntime(23300): Shutting down VM
11-17 18:35:04.343: D/dalvikvm(23300): GC_CONCURRENT freed 102K, 89% free 490K/4096K, paused 0ms+1ms, total 6ms
11-17 18:35:04.343: D/jdwp(23300): Got wake-up signal, bailing out of select
11-17 18:35:04.343: D/dalvikvm(23300): Debugger has detached; object registry had 1 entries
11-17 18:35:04.343: D/dalvikvm(23335): Late-enabling CheckJNI
11-17 18:35:04.353: I/ActivityManager(364): Start proc osgearth.Example for activity osgearth.Example/.osgViewer: pid=23335 uid=10064 gids={3003, 1015, 1028}
11-17 18:35:04.353: I/dalvikvm(23335): Turning on JNI app bug workarounds for target SDK version 10...
11-17 18:35:04.373: E/jdwp(23335): Failed sending reply to debugger: Broken pipe
11-17 18:35:04.373: D/dalvikvm(23335): Debugger has detached; object registry had 1 entries
11-17 18:35:04.373: I/ActivityManager(364): Start proc com.metago.astro for broadcast com.metago.astro/.PackageReplacedReceiver: pid=23348 uid=10066 gids={3003, 1015, 1028}
11-17 18:35:04.373: I/ActivityManager(364): No longer want com.google.android.apps.maps:FriendService (pid 7633): hidden #16
11-17 18:35:04.483: V/PhoneStatusBar(471): setLightsOn(true)
11-17 18:35:04.533: D/libEGL(23335): loaded /system/lib/egl/libEGL_tegra.so
11-17 18:35:04.533: D/dalvikvm(23348): GC_CONCURRENT freed 243K, 9% free 7510K/8199K, paused 5ms+4ms, total 60ms
11-17 18:35:04.533: D/dalvikvm(23348): WAIT_FOR_CONCURRENT_GC blocked 35ms
11-17 18:35:04.533: I/ActivityManager(364): Start proc com.google.android.apps.maps:FriendService for broadcast com.google.android.apps.maps/com.google.googlenav.friend.android.ServiceReceiver: pid=23361 uid=10034 gids={3003, 1015, 1028}
11-17 18:35:04.573: D/libEGL(23335): loaded /system/lib/egl/libGLESv1_CM_tegra.so
11-17 18:35:04.593: D/libEGL(23335): loaded /system/lib/egl/libGLESv2_tegra.so
11-17 18:35:04.603: W/EGLview(23335): creating OpenGL ES 2.0 context
11-17 18:35:04.653: D/dalvikvm(23335): Trying to load lib /data/data/osgearth.Example/lib/libosgNativeLib.so 0x42414b68
11-17 18:35:04.663: I/ActivityManager(364): Displayed osgearth.Example/.osgViewer: +329ms
11-17 18:35:04.763: D/dalvikvm(23361): GC_CONCURRENT freed 168K, 8% free 7586K/8199K, paused 37ms+4ms, total 83ms
11-17 18:35:04.763: D/dalvikvm(23361): WAIT_FOR_CONCURRENT_GC blocked 46ms
11-17 18:35:04.823: D/dalvikvm(23335): Added shared lib /data/data/osgearth.Example/lib/libosgNativeLib.so 0x42414b68
11-17 18:35:04.823: D/dalvikvm(23335): No JNI_OnLoad found in /data/data/osgearth.Example/lib/libosgNativeLib.so 0x42414b68, skipping init
11-17 18:35:04.823: E/OSGANDROID(23335): Initializing geometry


Galaxy S2 running 4.0.4


11-17 18:38:33.400: D/jdwp(5701): Got wake-up signal, bailing out of select
11-17 18:38:33.400: D/dalvikvm(5701): Debugger has detached; object registry had 1 entries
11-17 18:38:33.405: D/dalvikvm(5722): Late-enabling CheckJNI
11-17 18:38:33.405: I/ActivityManager(1981): Start proc app.processName for activity hostingNameStr: pid=5722 uid=10015 gids={3003, 1015, 1023}
11-17 18:38:33.410: D/GLSurfaceViewGroup(2230): Skipped drawing due to suspendDrawingUntilResume()
11-17 18:38:33.435: I/dalvikvm(5722): Turning on JNI app bug workarounds for target SDK version 10...
11-17 18:38:33.465: I/ApplicationUsage(1981): handleMessage : MSG_UPDATE_USAGE_DB
11-17 18:38:33.465: I/ApplicationUsage(1981): Updating Usage Statistics in DB @ 1353177513472
11-17 18:38:33.540: D/dalvikvm(1981): GC_EXPLICIT freed 778K, 42% free 15931K/27079K, paused 3ms+7ms
11-17 18:38:33.545: I/Launcher(2230): onWindowFocusChanged(false)
11-17 18:38:33.545: D/DEFERED_APP_VISIBILITY(1981): tweaking closing app
11-17 18:38:33.570: I/ActivityManager(1981): Start proc app.processName for broadcast hostingNameStr: pid=5735 uid=10012 gids={3003, 1015, 1023}
11-17 18:38:33.575: I/ActivityManager(1981): No longer want app.processName (pid 5208): hidden #26
11-17 18:38:33.585: D/GLSurfaceViewGroup(2230): Skipped drawing due to suspendDrawingUntilResume()
11-17 18:38:33.640: W/SurfaceView(2230): CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false
11-17 18:38:33.645: I/SurfaceFlinger(1820): id=105(1) createSurface 0x28f84 (1x1),1 flag=0, osgViewer
11-17 18:38:33.645: V/PhoneStatusBar(2103): setLightsOn(true)
11-17 18:38:33.650: I/ActivityThread(5735): Pub com.google.android.finsky.QSBSuggestionsProvider2: com.google.android.finsky.providers.QSBSuggestionsProvider
11-17 18:38:33.650: I/ActivityThread(5735): Pub com.google.android.finsky.AppIconProvider: com.google.android.finsky.providers.AppIconProvider
11-17 18:38:33.650: I/ActivityThread(5735): Pub com.google.android.finsky.RecentSuggestionsProvider: com.google.android.finsky.providers.RecentSuggestionsProvider
11-17 18:38:33.675: I/SurfaceFlinger(1820): id=106(2) createSurface 0x2b954 (480x652),1 flag=0, SurfaceView
11-17 18:38:33.690: D/dalvikvm(5735): GC_CONCURRENT freed 148K, 4% free 9433K/9735K, paused 2ms+1ms
11-17 18:38:33.690: D/libEGL(5722): loaded /system/lib/egl/libEGL_mali.so
11-17 18:38:33.695: D/libEGL(5722): loaded /system/lib/egl/libGLESv1_CM_mali.so
11-17 18:38:33.705: D/libEGL(5722): loaded /system/lib/egl/libGLESv2_mali.so
11-17 18:38:33.720: D/(5722): Device driver API match
11-17 18:38:33.720: D/(5722): Device driver API version: 10
11-17 18:38:33.720: D/(5722): User space API version: 10 
11-17 18:38:33.720: D/(5722): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Fri May  4 10:32:42 KST 2012 
11-17 18:38:33.725: I/ActivityManager(1981): Displayed shortComponentName: +348ms
11-17 18:38:33.730: I/ClipboardServiceEx(1981): mCBPickerDialog enter case. MSG_DISMISS_DIALOG
11-17 18:38:33.735: D/CLIPBOARD(2230): Hide Clipboard dialog at Starting input: finished by someone else... !
11-17 18:38:33.735: I/ClipboardServiceEx(1981): mCBPickerDialog enter case. MSG_DISMISS_DIALOG
11-17 18:38:33.740: W/EGLview(5722): creating OpenGL ES 2.0 context
11-17 18:38:33.750: D/CLIPBOARD(5722): Hide Clipboard dialog at Starting input: finished by someone else... !
11-17 18:38:33.750: I/ClipboardServiceEx(1981): mCBPickerDialog enter case. MSG_DISMISS_DIALOG
11-17 18:38:33.755: D/dalvikvm(5722): Trying to load lib /data/data/osgearth.Example/lib/libosgNativeLib.so 0x4157a988
11-17 18:38:33.900: I/ApplicationPolicy(1981): getActualApplicationStateEnabled() : true
11-17 18:38:33.900: W/WifiStateTracker(1981): getNetworkInfo : NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
11-17 18:38:33.900: E/WifiP2pStateTracker(1981): getNetworkInfo : NetworkInfo: type: wifi_p2p[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: false
11-17 18:38:33.910: W/WifiStateTracker(1981): getNetworkInfo : NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
11-17 18:38:33.910: E/WifiP2pStateTracker(1981): getNetworkInfo : NetworkInfo: type: wifi_p2p[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: false
11-17 18:38:33.915: I/SurfaceFlinger(1820): id=104 Removed Example idx=6 Map Size=7
11-17 18:38:33.915: I/SurfaceFlinger(1820): id=104 Removed Example idx=-2 Map Size=7
11-17 18:38:33.930: D/dalvikvm(5735): DexOpt: couldn't find field Landroid/app/Notification;.priority
11-17 18:38:33.930: W/dalvikvm(5735): VFY: unable to resolve instance field 62
11-17 18:38:33.930: D/dalvikvm(5735): VFY: replacing opcode 0x59 at 0x004a
11-17 18:38:33.940: D/Finsky(5735): [1] DailyHygiene.goMakeHygieneIfDirty: No need to run daily hygiene.
11-17 18:38:34.015: D/dalvikvm(5735): GC_CONCURRENT freed 301K, 5% free 9588K/9991K, paused 2ms+2ms

Hope that can help someone help me ;)

Thanks
Tom

RichardC

unread,
Nov 19, 2012, 8:28:56 AM11/19/12
to andro...@googlegroups.com
Try adding JNI_OnLoad() (return JNI_VERSION_1_6) and putting a log line into it.

Thomas Hogarth

unread,
Nov 19, 2012, 12:02:13 PM11/19/12
to andro...@googlegroups.com
Hi Richard

So I've tried that with no luck, here's my JNI_OnLoad

extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    __android_log_write(ANDROID_LOG_ERROR, "OSGANDROID", "Entered JNI_OnLoad"); 
    return JNI_VERSION_1_6;
}

I also added some output around the loadlibrary call

Log.w("osgNativeLib", "About to load lib");
System.loadLibrary("osgNativeLib");
Log.w("osgNativeLib", "Lib loaded");


Here is what I get on nexus 7

11-19 16:56:13.893: W/osgNativeLib(1622): About to load lib
11-19 16:56:13.893: D/dalvikvm(1622): Trying to load lib /data/data/osgearth.Example/lib/libosgNativeLib.so 0x414f52e0
11-19 16:56:14.003: D/dalvikvm(1622): Added shared lib /data/data/osgearth.Example/lib/libosgNativeLib.so 0x414f52e0
11-19 16:56:14.003: E/OSGANDROID(1622): Entered JNI_OnLoad
11-19 16:56:14.003: W/osgNativeLib(1622): Lib loaded

Here's Galaxy S2

11-19 17:00:01.810: W/osgNativeLib(5278): About to load lib
11-19 17:00:01.810: D/dalvikvm(5278): Trying to load lib /data/data/osgearth.Example/lib/libosgNativeLib.so 0x41559b70
11-19 17:00:01.830: D/CLIPBOARD(5278): Hide Clipboard dialog at Starting input: finished by someone else... !

No more output after that as the app does actually seem to freeze but not crash.

RichardC

unread,
Nov 19, 2012, 2:36:25 PM11/19/12
to andro...@googlegroups.com
The only thing I can think of is that there could be a problem with initialization of statics.

Are you loading the library on your main (UI) thread?  If you are I would expect to see an Application Not Responding message after about 5 secs in the LogCat.  If you are loading on a background thread try loading on the UI thread.

Thomas Hogarth

unread,
Nov 22, 2012, 5:32:05 PM11/22/12
to andro...@googlegroups.com
Hi Richard,

So I've tried moving my loadLibary call out of a static in my nativelib class and into the create of my main activity but still no luck.

So I started removing various bit from the project, if i reduce the project down to just openscenegraph code then it works. I found that if I include one of 
osgEarths plugins and try and load a file, that is what is causing the problem. I imagine if i do the load on a button press then I might get a chance to attach
the debugger.

Thanks for the advice, if it's something generic causing the issue I'll be sure to report it here for others to find.

Tom

joebowbeer

unread,
Nov 25, 2012, 11:28:53 AM11/25/12
to andro...@googlegroups.com
Is this related to the new position-independent executable feature (APP_PIE) which is not compatible with 4.0 and below?

Try adding APP_PLATFORM to Application.mk and/or explicitly disabling APP_PIE:

APP_PLATFORM := android-<minSdkVersion>
APP_PIE := false

Thomas Hogarth

unread,
Nov 26, 2012, 5:52:40 PM11/26/12
to andro...@googlegroups.com
Hi Joe

I've tried your suggestion, Adding APP_PIE := fale didn't work for me unfortunately.

I did a little more testing and have now realised that the issue occurs if I allocate any class type from the osgEarth lib.

So if my demo consists of just an OpenSceneGraph setup, it will run, but if I add just this line

Map* map = new Map();

Then the app will crash, but only on 4.0 or less. I will double check now, but the ndk-build setup should be the same
for both the osg and osgearth libs, but for some reason allocating stuff from the osgearth lib causes the crash.

Any help would be appreciated.
Tom

David Turner

unread,
Nov 27, 2012, 11:29:46 AM11/27/12
to andro...@googlegroups.com
On Sun, Nov 25, 2012 at 5:28 PM, joebowbeer <joe.b...@gmail.com> wrote:
Is this related to the new position-independent executable feature (APP_PIE) which is not compatible with 4.0 and below?

Try adding APP_PLATFORM to Application.mk and/or explicitly disabling APP_PIE:

APP_PLATFORM := android-<minSdkVersion>
APP_PIE := false

For the record, the PIE flag only affects executables, it doesn't do anything for shared libraries.

 
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/V52rqykrn-cJ.

Thomas Hogarth

unread,
Dec 2, 2012, 6:14:33 PM12/2/12
to andro...@googlegroups.com
So I've investigated further.

After a bit of fiddling I've managed to get the entire setup to build with NDK r7b, However my issue still exists.

The same apk will run on my Nexus 7 (4.1.2), but fails to load my lib on Galaxy S2 (4.0.1) and falis on HTC EVO 3D (4.0.3).

I don't get any unresolved dependancies etc, and seaming if osgEarth is linked into the project, even if the code is note called,
the lib stops loading on 4.0 or less.


Any ideas would be greatly appreciated.
Tom

Alex Cohn

unread,
May 1, 2013, 8:28:46 AM5/1/13
to andro...@googlegroups.com
On Monday, December 3, 2012 1:14:33 AM UTC+2, Thomas Hogarth wrote:
So I've investigated further.

After a bit of fiddling I've managed to get the entire setup to build with NDK r7b, However my issue still exists.

The same apk will run on my Nexus 7 (4.1.2), but fails to load my lib on Galaxy S2 (4.0.1) and falis on HTC EVO 3D (4.0.3).

I don't get any unresolved dependancies etc, and seaming if osgEarth is linked into the project, even if the code is note called,
the lib stops loading on 4.0 or less.


Any ideas would be greatly appreciated.
Tom

I know some time passed since you posted in this thread, but only today it popped into my attention.

There was a problem with 4.0.something that was fixed later which caused armeabi and armeabi-v7a versions of the same .so to be not chosen correctly. Try to only build and package only one of them (set APP_ABI=armeabi-v7a on ndk-build command line), and maybe it will help.

BR,
Alex

niko20

unread,
May 21, 2013, 8:45:52 AM5/21/13
to andro...@googlegroups.com
Yes, the problem is that if you have an *.so file, and you have multiple folders (armeabi and armeabiv7), you must have *ALL* the exact same SO file list in both folders. You can't for example have "lib1.so, lib2.so" in the armeabi folder, and then only have "lib2.so" in the armeabiv7 folder. Android 4.0 knows to only load the second library from the armeabiv7 folder, but lower versions do not (some type of bug), and they will fail to load the "lib1.so" entirely. Each folder has to have the entire set of *.so files that you need.

-niko
Reply all
Reply to author
Forward
0 new messages