Trouble with Spotify integration: App ID error on physical device

Hey everyone! I’m stuck with a weird issue in my Android app that uses the Spotify API. Everything works fine on the emulator but I’m hitting a snag on my actual phone.

When I try to play a song after user authentication on my phone, I get an INVALID_APP_ID error. Oddly enough, if I uninstall the Spotify app from my phone, my app works without crashes.

I’ve followed the Spotify API tutorial to set up the connection. Here’s a snippet of my authentication code:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    
    if (requestCode == MY_REQUEST_CODE) {
        val response = AuthenticationClient.getResponse(resultCode, data)
        if (response.type == AuthenticationResponse.Type.TOKEN) {
            val playerConfig = Config(this, response.accessToken, MY_CLIENT_ID)
            SpotifyPlayer.create(playerConfig, object : SpotifyPlayer.InitializationObserver {
                override fun onInitialized(player: SpotifyPlayer) {
                    spotifyPlayer = player
                    spotifyPlayer.addConnectionStateCallback(this@MainActivity)
                    spotifyPlayer.addPlayerNotificationCallback(this@MainActivity)
                }

                override fun onError(error: Throwable) {
                    Log.e(TAG, "Player init failed: ${error.message}")
                }
            })
        }
    }
}

Any ideas on how to fix this? Thanks in advance!

In my experience, the error you are seeing can be due to a mismatch between your app’s registration details on Spotify’s Developer Dashboard and your actual app settings. It may help to verify that your AndroidManifest package name exactly matches the package registered in your Spotify Dashboard and that you are using the correct Client ID. Also, ensure that your app’s SHA1 fingerprint is correctly added. Sometimes residual data from the Spotify app on the device can cause issues, so clearing its cached data might resolve the error. If the problem persists, consider creating a new app in the Developer Dashboard with new credentials.

I’ve encountered similar issues with Spotify integration before. One potential solution is to double-check your app’s package name in both the AndroidManifest and the Spotify Developer Dashboard—they must match exactly. Also, ensure you’re using the correct Client ID for your app.

If you’re using a debug build on your physical device, verify that the debug SHA-1 fingerprint is added to your Spotify Dashboard. An error can occur if the app signature doesn’t match what Spotify expects.

Finally, try clearing the Spotify app’s data on your phone, as cached authentication data might cause conflicts. If problems persist, consider creating a new app in the Spotify Dashboard and using the new credentials.