2

I've modified the jukebox example to run on Android, but it segfaults miserably when trying to call the sp_session_create() function.

Basically - I have a helloworld Android app with a button. When pressed it calls this function, which crashes on sp_session_create():

JNIEXPORT void JNICALL Java_com_holidaystudios_unispot_uniSpot_prepareSpotify() {
    sp_session *sp;
    sp_error err;
    const char *username = NULL;
    const char *password = NULL;

    username = __USERNAME;
    password = __PASSWORD;
    g_listname = __PLAYLIST;

    UNISPOT_DEBUG("prepareSpotify() - 1\n");
    audio_init(&g_audiofifo);
    UNISPOT_DEBUG("prepareSpotify() - 2\n");

    /* Create session */
    spconfig.application_key_size = g_appkey_size;
    UNISPOT_DEBUG("prepareSpotify() - 3 %d, %p, %p (%p)\n", g_appkey_size, &spconfig, &sp, sp_session_create);

    err = sp_session_create(&spconfig, &sp);
    UNISPOT_DEBUG("prepareSpotify() - 4\n");
.
.
.

Here's the logcat output which shows the segfault:

I/UNISPOT|NDK( 5951): prepareSpotify() - 1
I/UNISPOT|NDK( 5951): prepareSpotify() - 2
I/UNISPOT|NDK( 5951): prepareSpotify() - 3 321, 0x575115ac, 0xbec4052c (0x5b4107b4)
F/libc    ( 5951): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
I/DEBUG   (31750): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (31750): Build fingerprint: 'google/yakju/maguro:4.0.4/IMM76I/330937:user/release-keys'
I/DEBUG   (31750): pid: 5951, tid: 5951  >>> com.holidaystudios.unispot <<<
I/DEBUG   (31750): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
I/DEBUG   (31750):  r0 0155d708  r1 4006162c  r2 00000000  r3 5b47add8
I/DEBUG   (31750):  r4 0155d708  r5 5b47e740  r6 57508d48  r7 0155d708
I/DEBUG   (31750):  r8 bec40460  r9 bec4052c  10 0155d768  fp 0155d768
I/DEBUG   (31750):  ip 40061474  sp bec40340  lr 5b410a7c  pc 5b4104f4  cpsr 60000010
I/DEBUG   (31750):  d0  00656c6f736e6f63  d1  72616364732f2061
I/DEBUG   (31750):  d2  61726f74532f2f63  d3  7865646e692f6568
I/DEBUG   (31750):  d4  0000000000000000  d5  0000000000000000
I/DEBUG   (31750):  d6  0000000000000000  d7  00f92b8000000000
I/DEBUG   (31750):  d8  0000000000000000  d9  0000000000000000
I/DEBUG   (31750):  d10 0000000000000000  d11 0000000000000000
I/DEBUG   (31750):  d12 0000000000000000  d13 0000000000000000
I/DEBUG   (31750):  d14 0000000000000000  d15 0000000000000000
I/DEBUG   (31750):  d16 416f257010000000  d17 3fe0000000000000
I/DEBUG   (31750):  d18 0000000000000000  d19 3fe5555560000000
I/DEBUG   (31750):  d20 0000000000000000  d21 0000000000000000
I/DEBUG   (31750):  d22 3ff0000000000000  d23 0000000000000000
I/DEBUG   (31750):  d24 0000000000000000  d25 3fe5555560000000
I/DEBUG   (31750):  d26 0000000000000000  d27 3fe5555560000000
I/DEBUG   (31750):  d28 0000000000000000  d29 3ff0000000000000
I/DEBUG   (31750):  d30 3ff0000000000000  d31 be23e4f5df600000
I/DEBUG   (31750):  scr 80000013
I/DEBUG   (31750): 
I/DEBUG   (31750):          #00  pc 0016b4f4  /data/data/com.holidaystudios.unispot/lib/libspotify.so
I/DEBUG   (31750):          #01  lr 5b410a7c  /data/data/com.holidaystudios.unispot/lib/libspotify.so
I/DEBUG   (31750): 
I/DEBUG   (31750): code around pc:
I/DEBUG   (31750): 5b4104d4 e59f50ac e59f30ac e08f5005 e7953003  .P...0...P...0..
I/DEBUG   (31750): 5b4104e4 e5902004 e2833008 e5803000 e1a04000  . ...0...0...@..
I/DEBUG   (31750): 5b4104f4 e5923000 e1a00002 e1a0e00f e593f178  .0..........x...
I/DEBUG   (31750): 5b410504 e5943004 e3530000 0a000005 e3a02000  .0....S...... ..
I/DEBUG   (31750): 5b410514 e1a00003 e5842004 e5933000 e1a0e00f  ..... ...0......
I/DEBUG   (31750): 
I/DEBUG   (31750): code around lr:
I/DEBUG   (31750): 5b410a5c ebfaaa07 e5c7822c e1a00007 ebfffdec  ....,...........
I/DEBUG   (31750): 5b410a6c e3500000 1a000005 e1a00007 ebfffe94  ..P.............
I/DEBUG   (31750): 5b410a7c e1a00007 ebfc951c e3a04002 ea00009d  .........@......
I/DEBUG   (31750): 5b410a8c e1a01006 e4d13001 e5c73064 e3a02080  .....0..d0... ..
I/DEBUG   (31750): 5b410a9c e2870065 ebfaa8ee e3a020c0 e2861081  e........ ......
I/DEBUG   (31750): 
I/DEBUG   (31750): stack:
I/DEBUG   (31750):     bec40300  0155d9c8  [heap]
I/DEBUG   (31750):     bec40304  5b37f080  /data/data/com.holidaystudios.unispot/lib/libspotify.so
I/DEBUG   (31750):     bec40308  0155d708  [heap]
I/DEBUG   (31750):     bec4030c  5b47e740  /data/data/com.holidaystudios.unispot/lib/libspotify.so
I/DEBUG   (31750):     bec40310  57508d48  /data/data/com.holidaystudios.unispot/lib/liblespot.so
I/DEBUG   (31750):     bec40314  5b410230  /data/data/com.holidaystudios.unispot/lib/libspotify.so
I/DEBUG   (31750):     bec40318  00000400  
I/DEBUG   (31750):     bec4031c  bec40460  [stack]
I/DEBUG   (31750):     bec40320  bec4052c  [stack]
I/DEBUG   (31750):     bec40324  0155d768  [heap]
I/DEBUG   (31750):     bec40328  0155d768  [heap]
I/DEBUG   (31750):     bec4032c  5b33f988  /data/data/com.holidaystudios.unispot/lib/libspotify.so
I/DEBUG   (31750):     bec40330  00000000  
I/DEBUG   (31750):     bec40334  00040000  
I/DEBUG   (31750):     bec40338  df0027ad  
I/DEBUG   (31750):     bec4033c  00000000  
I/DEBUG   (31750): #00 bec40340  575115ac  /data/data/com.holidaystudios.unispot/lib/liblespot.so
I/DEBUG   (31750):     bec40344  5b47e740  /data/data/com.holidaystudios.unispot/lib/libspotify.so
I/DEBUG   (31750):     bec40348  57508d48  /data/data/com.holidaystudios.unispot/lib/liblespot.so
I/DEBUG   (31750):     bec4034c  5b410a7c  /data/data/com.holidaystudios.unispot/lib/libspotify.so
I/DEBUG   (31750):     bec40350  00000000  
I/DEBUG   (31750):     bec40354  57e90026  /system/framework/framework.odex
I/DEBUG   (31750):     bec40358  41678018  /dev/ashmem/dalvik-heap (deleted)
I/DEBUG   (31750):     bec4035c  bec404e4  [stack]
I/DEBUG   (31750):     bec40360  00000000  
I/DEBUG   (31750):     bec40364  00010001  
I/DEBUG   (31750):     bec40368  00000000  
I/DEBUG   (31750):     bec4036c  00000000  
I/DEBUG   (31750):     bec40370  416a9ee8  /dev/ashmem/dalvik-heap (deleted)
I/DEBUG   (31750):     bec40374  416a9ee8  /dev/ashmem/dalvik-heap (deleted)
I/DEBUG   (31750):     bec40378  41678018  /dev/ashmem/dalvik-heap (deleted)
I/DEBUG   (31750):     bec4037c  00000024  
I/DEBUG   (31750):     bec40380  01303740  [heap]
I/DEBUG   (31750):     bec40384  408a39b8  
I/BootReceiver(  189): Copying /data/tombstones/tombstone_00 to DropBox (SYSTEM_TOMBSTONE)
I/WindowManager(  189): WIN DEATH: Window{416abe40 com.holidaystudios.unispot/com.holidaystudios.unispot.uniSpot paused=false}
I/ActivityManager(  189): Process com.holidaystudios.unispot (pid 5951) has died.

Any ideas?

  • code for `sp_session_create` ? I would suggest to re-edit your question to include more information, as to that `sp_session_create`, why is that in there as the last parameter to `UNISPOT_DEBUG`? Is that the line where the actual crash is at? – t0mm13b Jul 08 '12 at 18:09
  • sp_session_create() is an internal function of libspotify.so. This is a proprietary library by Spotify.. So unfortunately I do not have the source code. I was directed to this site from the Spotify developer page... So, using the spotify tag I hope someone who knows a bit more about the lib will answer... The reason sp_session_create is sent as a parameter to UNISPOT_DEBUG is to print out the address where that function has been loaded. (Wanted to make sure the function pointer is not NULL..) The crash is after the UNISPOT_DEBUG() line. (The pc is within libspotify.so if you look in the log..) – user1510144 Jul 08 '12 at 18:42
  • question, is that library targetting the right ARM chipset for your app and handset? Have you not posted to the spotify developer's forum itself? That would seem a more appropriate place to get a right answer instead of here :) – t0mm13b Jul 08 '12 at 18:46
  • I hope so! It is libspotify 12.1.51, the ARM/Android version as available on https://developer.spotify.com/download/libspotify/libspotify-12.1.51-Android-arm-release.tar.gz – user1510144 Jul 08 '12 at 19:05
  • There's Armv5/Armv6 and Armv7.[different ARM libs](https://developer.spotify.com/technologies/libspotify/) Just for your sanity checking, since the clue is Maguro which is Galaxy Nexus, Armv7 is the one to use. – t0mm13b Jul 08 '12 at 19:08
  • It seems to be right: arm-linux-androideabi-objdump -p libs/armeabi/libspotify.so | tail -n 2 private flags = 5000002: [Version5 EABI] [has entry point] that is it seems to be armeabi, and follow ARMv5TE which according to the Android NDK is supported. – user1510144 Jul 08 '12 at 19:22
  • In that case, I seriously suggest you re-direct the question over to the spotify's developer forums. I find it bad form that they actually sent you over here to StackOverflow, when the issue is clearly on the spotify's end. You need to wait until someone actually answers that question. – t0mm13b Jul 08 '12 at 19:26
  • Hehe, thanks anyway... Just as a side note - I'm not terribly impressed with the packaging of their library at all, actually.. No good examples for the platform they are actually targeting with the package, and not any of the fundamentally required documentation! – user1510144 Jul 08 '12 at 19:34
  • that's *pretty bad* of them... like what do they expect devs like you to do? If they want to increase their penetration of spotify, provide darn good examples, docs etc... some support!!!! well... sorry mate, could not be of further help on this. :( – t0mm13b Jul 08 '12 at 19:37

2 Answers2

2

I'm posting this as an answer since it seems I need more reputation to answer comments, but, to answer @KurtCobain's request: you also need to make sure that your cache_location and settings_location point to a valid, writable location on your android device. The default value in the spotify examples for those variables is "tmp". This won't work and will cause your app to crash.

Instead (at least as a temporary, straightforward solution) you could use something like Context.getCacheDir in your activity to retrieve a valid temporary folder, and use this value in your C code (see this question for more info on that).

Community
  • 1
  • 1
jjst
  • 2,631
  • 2
  • 22
  • 34
0

I finally figured out what the problem is. If your AndroidManifest.xml does not request the INTERNET permission (and possibly WRITE_EXTERNAL_STORAGE) it will crash... Unfortunately libspotify does not perform any checks on creating sockets and will therefore crash... I'd say it's actually a bug in libspotify... But anyhoo - here's what you need to add to your AndroidManifest.xml if you are having the same problem as I did:

  <uses-permission android:name="android.permission.INTERNET" />

Possibly also this:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • I am trying to do exactly the same thing but despite make the above permission changes - I am still seeing the crash at sp_session_create.I have tested this on emulator as well as device.@user1510144 - can you any other input ? I am trying to build the local_files example. – KurtCobain Sep 21 '12 at 10:07