Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:29:48+00:00 2026-06-13T18:29:48+00:00

I’m trying to run the provided Spotify stub example on android, but the native

  • 0

I’m trying to run the provided Spotify stub example on android, but the native code seems to ‘crash’ when attempting to create a session. Here is what my code looks like.

Native code:

JNIEXPORT int JNICALL
Java_com_test_spotify_SpotifyActivity_spotifyInit( JNIEnv*  env, jobject  this,jstring     username, jstring     password,jstring cache,jstring tracefile)
{

const char* name = (*env)->GetStringUTFChars(env, username, NULL);
const char* pwd = (*env)->GetStringUTFChars(env, password, NULL);
const char* cache_location = (*env)->GetStringUTFChars(env, cache, NULL);
const char* trace_file = (*env)->GetStringUTFChars(env, tracefile, NULL);

if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "User name: %s", name);
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "Password: %s", pwd);
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "Cache %s", cache_location);
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "Trace file %s", trace_file);

return spotify_init(name,pwd,cache_location,trace_file);
}

int spotify_init(const char *username,const char *password,const char* cache_location,const char* trace_file)
{
int next_timeout = 0;
pthread_mutex_init(&notify_mutex, NULL);
pthread_cond_init(&notify_cond, NULL);

sp_session_config config;
sp_error error;
sp_session *session;

config.api_version = SPOTIFY_API_VERSION;
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "SPOTIFY_API_VERSION: %d",config.api_version);

config.cache_location = cache_location;
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "config.cache_location: %s",config.cache_location);

config.settings_location = cache_location;
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "config.settings_location: %s",config.settings_location);

config.tracefile = trace_file;
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "config.tracefile: %s",config.tracefile);

config.application_key = g_appkey;

config.application_key_size = g_appkey_size;
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "g_appkey_size: %d",config.application_key_size);

config.user_agent = USER_AGENT;
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "USER_AGENT: %s",config.user_agent);

// Register the callbacks.
config.callbacks = &callbacks;
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "defined callbacks");
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "creating session...");
error = sp_session_create(&config, &session);

if (SP_ERROR_OK != error) {
    fprintf(stderr, "failed to create session: %s\n",
                    sp_error_message(error));
    if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "error code: %d",error);
    return 2;
}
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "Session created!");

// Login using the credentials given on the command line.
error = sp_session_login(session, username, password, 0,NULL);

if (SP_ERROR_OK != error) {
    fprintf(stderr, "failed to login: %s\n",
                    sp_error_message(error));
    if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "error code: %d",error);
    return 3;
}
if(DEBUG_MODE) __android_log_print(ANDROID_LOG_INFO, "spotifyInit", "User is logged in!");

g_session = session;
//session has been created

pthread_mutex_lock(&notify_mutex);
    for (;;) {
        if (next_timeout == 0) {
            while(!notify_events)
                pthread_cond_wait(&notify_cond, &notify_mutex);
        } else {
            struct timespec ts;

    #if _POSIX_TIMERS > 0
            clock_gettime(CLOCK_REALTIME, &ts);
    #else
            struct timeval tv;
            gettimeofday(&tv, NULL);
            TIMEVAL_TO_TIMESPEC(&tv, &ts);
    #endif

            ts.tv_sec += next_timeout / 1000;
            ts.tv_nsec += (next_timeout % 1000) * 1000000;

            while(!notify_events) {
                if(pthread_cond_timedwait(&notify_cond, &notify_mutex, &ts))
                    break;
            }
        }

        // Process libspotify events
        notify_events = 0;
        pthread_mutex_unlock(&notify_mutex);

        do {
            sp_session_process_events(g_session, &next_timeout);
        } while (next_timeout == 0);

        pthread_mutex_lock(&notify_mutex);
    }
    return 0;
}

Android activity:

public class SpotifyActivity extends Activity {
EditText logText;

static {
System.loadLibrary("spotify");
System.loadLibrary("spotifystub");
}

public native int spotifyInit(String username, String password, String cacheLocation, String traceFile);

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
logText = (EditText) findViewById(R.id.editTextLog);

String cache = File.separator + "data" + File.separator + "data" + File.separator + "com.test.spotify" + File.separator + getCacheDir().getName();//set to empty string to disable cache
String traceFile = cache + File.separator + "trace_file.txt";

try {
    File dir = new File(cache);
    if (!dir.exists()) {
    dir.mkdir();
    }
    File f = new File(traceFile);
    if (!f.exists()) {
    Log.w(getClass().getSimpleName(), "trace file does not exist, creating...");
    f.createNewFile();
    }
    int response = spotifyInit("test@mail.com", "testpwd", cache, traceFile);
    if (response == 0) {
    log("Session created!, code: " + response);
    } else {
    log("Something went wrong!, code: " + response);
    }
} catch (Exception e) {
    e.printStackTrace();
}

}

private void log(String logString) {
logText.append(logString);
logText.append("\n");
}
}

So when I run the app this is the logcat output i get followed by a crash

10-30 09:27:42.390: INFO/spotifyInit(552): User name: test@mail.com
10-30 09:27:42.390: INFO/spotifyInit(552): Password: testpwd
10-30 09:27:42.390: INFO/spotifyInit(552): Cache /data/data/com.test.spotify/cache
10-30 09:27:42.390: INFO/spotifyInit(552): Trace file /data/data/com.test.spotify/cache/trace_file.txt
10-30 09:27:42.400: INFO/spotifyInit(552): SPOTIFY_API_VERSION: 12
10-30 09:27:42.400: INFO/spotifyInit(552): config.cache_location: /data/data/com.test.spotify/cache
10-30 09:27:42.400: INFO/spotifyInit(552): config.settings_location: /data/data/com.test.spotify/cache
10-30 09:27:42.400: INFO/spotifyInit(552): config.tracefile: /data/data/com.test.spotify/cache/trace_file.txt
10-30 09:27:42.400: INFO/spotifyInit(552): g_appkey_size: 321
10-30 09:27:42.400: INFO/spotifyInit(552): USER_AGENT: spotifydemo
10-30 09:27:42.400: INFO/spotifyInit(552): defined callbacks
10-30 09:27:42.400: INFO/spotifyInit(552): creating session...
10-30 09:27:42.520: INFO/DEBUG(28): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-30 09:27:42.520: INFO/DEBUG(28): Build fingerprint: 'generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys'
10-30 09:27:42.520: INFO/DEBUG(28): pid: 552, tid: 552  >>> com.test.spotify <<<
10-30 09:27:42.520: INFO/DEBUG(28): signal 11 (SIGSEGV), fault addr 000000a9
10-30 09:27:42.520: INFO/DEBUG(28):  r0 0000000b  r1 80000000  r2 80808080  r3 00000073
10-30 09:27:42.520: INFO/DEBUG(28):  r4 bec56894  r5 80dd9740  r6 000000a9  r7 bec566c8
10-30 09:27:42.520: INFO/DEBUG(28):  r8 00118638  r9 bec56888  10 001239e0  fp 00000000
10-30 09:27:42.520: INFO/DEBUG(28):  ip 006f6d65  sp bec566b8  lr 80d6b8bc  pc 80d6b8dc  cpsr 20000010
10-30 09:27:42.622: INFO/DEBUG(28):          #00  pc 0016b8dc  /data/data/com.test.spotify/lib/libspotify.so
10-30 09:27:42.622: INFO/DEBUG(28):          #01  lr 80d6b8bc  /data/data/com.test.spotify/lib/libspotify.so
10-30 09:27:42.622: INFO/DEBUG(28): code around lr:
10-30 09:27:42.622: INFO/DEBUG(28): 80d6b8ac e3560000 0a0000fd e1a00006 ebfaa9c2 
10-30 09:27:42.622: INFO/DEBUG(28): 80d6b8bc e3500c01 8a0000f9 e5d63000 e3530000 
10-30 09:27:42.622: INFO/DEBUG(28): 80d6b8cc 0a0000f6 e5946024 e3560000 0a00000d 
10-30 09:27:42.622: INFO/DEBUG(28): stack:
10-30 09:27:42.630: INFO/DEBUG(28):     bec56678  c2e19b5e  
10-30 09:27:42.630: INFO/DEBUG(28):     bec5667c  7e587492  
10-30 09:27:42.630: INFO/DEBUG(28):     bec56680  4a7d74f0  
10-30 09:27:42.630: INFO/DEBUG(28):     bec56684  57b1fb47  
10-30 09:27:42.630: INFO/DEBUG(28):     bec56688  1c3e3207  
10-30 09:27:42.630: INFO/DEBUG(28):     bec5668c  e0fcf49a  
10-30 09:27:42.630: INFO/DEBUG(28):     bec56690  47ff6b89  
10-30 09:27:42.630: INFO/DEBUG(28):     bec56694  24bc6c79  
10-30 09:27:42.630: INFO/DEBUG(28):     bec56698  bbe6e9ce  
10-30 09:27:42.641: INFO/DEBUG(28):     bec5669c  dc9e8379  
10-30 09:27:42.641: INFO/DEBUG(28):     bec566a0  58221fd4  
10-30 09:27:42.641: INFO/DEBUG(28):     bec566a4  d3460398  
10-30 09:27:42.641: INFO/DEBUG(28):     bec566a8  bec56894  [stack]
10-30 09:27:42.641: INFO/DEBUG(28):     bec566ac  80dd9740  /data/data/com.test.spotify/lib/libspotify.so
10-30 09:27:42.641: INFO/DEBUG(28):     bec566b0  df002777  
10-30 09:27:42.641: INFO/DEBUG(28):     bec566b4  e3a070ad  
10-30 09:27:42.641: INFO/DEBUG(28): #00 bec566b8  00000007  
10-30 09:27:42.641: INFO/DEBUG(28):     bec566bc  0000098c  
10-30 09:27:42.641: INFO/DEBUG(28):     bec566c0  4003c290  /dev/ashmem/mspace/dalvik-heap/zygote/0 (deleted)
10-30 09:27:42.641: INFO/DEBUG(28):     bec566c4  bec56664  [stack]
10-30 09:27:42.650: INFO/DEBUG(28):     bec566c8  7362696c  
10-30 09:27:42.650: INFO/DEBUG(28):     bec566cc  69746f70  
10-30 09:27:42.650: INFO/DEBUG(28):     bec566d0  74207966  
10-30 09:27:42.650: INFO/DEBUG(28):     bec566d4  65636172  
10-30 09:27:42.650: INFO/DEBUG(28):     bec566d8  6f726620  
10-30 09:27:42.650: INFO/DEBUG(28):     bec566dc  3231206d  
10-30 09:27:42.650: INFO/DEBUG(28):     bec566e0  352e312e  
10-30 09:27:42.650: INFO/DEBUG(28):     bec566e4  38672e31  
10-30 09:27:42.650: INFO/DEBUG(28):     bec566e8  32396336  
10-30 09:27:42.650: INFO/DEBUG(28):     bec566ec  20333462  
10-30 09:27:42.660: INFO/DEBUG(28):     bec566f0  656c6552  
10-30 09:27:42.660: INFO/DEBUG(28):     bec566f4  20657361  
10-30 09:27:42.660: INFO/DEBUG(28):     bec566f8  72646e41  
10-30 09:27:42.660: INFO/DEBUG(28):     bec566fc  2d64696f  

Looking at the logcat output the code runs upto the point where we want to create the session (error = sp_session_create(&config, &session);) , then it crashes. I’ve spent hours trying to get this simple example to work, what am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:29:49+00:00Added an answer on June 13, 2026 at 6:29 pm

    Make sure you memset out your sp_session_config struct to 0 before using it. Otherwise, you’ll get a struct filled with garbage which will cause crashes.

    For example:

    sp_session_config config;
    memset(&config, 0, sizeof(config));
    

    It’s best practice to do this for all structs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.