lufinkey/react-native-spotify

java.lang.NoSuchFieldError: no "Ljava/lang/String;" field "oauthToken" in class "Lcom/spotify/sdk/android/player/Config;" or its superclasses

Mobuis opened this issue · 17 comments

Hi,

I'm currently trying to build my project in Release mode on Android and it keep crashing when using Spotify.login() or Spotify.loginWithSession().

I'm building to a Google Pixel 3 with API 28.
In debug mode (on iOS and Android) it works like a charm but in release (only for Android) it's not working.

The error :

java.lang.NoSuchFieldError: no "Ljava/lang/String;" field "oauthToken" in class "Lcom/spotify/sdk/android/player/Config;" or its superclasses
JNI DETECTED ERROR IN APPLICATION: JNI FindClass called with pending exception java.lang.NoSuchFieldError: no "Ljava/lang/String;" field "oauthToken" in class "Lcom/spotify/sdk/android/player/Config;" or its superclasses
 (Throwable with no stack trace) 
     in call to FindClass
     from java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader)
 "main" prio=5 tid=1 Runnable
   | group="main" sCount=0 dsCount=0 flags=0 obj=0x757daee0 self=0xe635c000
   | sysTid=10286 nice=-4 cgrp=default sched=0/0 handle=0xeafe1494
   | state=R schedstat=( 7054347386 3132893614 5553 ) utm=389 stm=316 core=0 HZ=100
   | stack=0xff188000-0xff18a000 stackSize=8MB
   | held mutexes= "mutator lock"(shared held)

React: 16.8.3
React Native: 0.59.9
RN Spotify SDK: 1.2.10
Android API: 28 (v9.0 Pie)
Gradle: 5.4.1
Android Plugin Version: 3.4.0

This looks like an error coming from the actual streaming SDK itself, which is unfortunately deprecated now. I don't think there's really much I can do to fix this. Is it possible to use the debug version for release on Android?

It may also work if you use an older API version, although I'm not entirely sure.

Thanks for your quick response !

Is it possible to use the debug version for release on Android?

I really don't know..

It may also work if you use an older API version, although I'm not entirely sure.

Like how ?

You said you were using Android API 28. Try using an older version.

I've tested with Android API 26/27 right now, it's not working..

Then I'm honestly not sure. I'd try and see if you can force using the debug version of the android streaming SDK

Yeah, I don't know how to do force one package to use debug version haha
I'll try to find it and keep an eye here if you have time to test also !

It seems "enableProguardInReleaseBuilds" (minifyEnabled = true) is crashing the app

From the app's gradle file !
I didn't try from the react native module, maybe it's a good idea

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
	buildTypes {
	        release {
	            lintOptions {
	                checkReleaseBuilds false
	                abortOnError false
	            }
	
	            minifyEnabled enableProguardInReleaseBuilds
	            shrinkResources enableProguardInReleaseBuilds
	            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
	            signingConfig signingConfigs.release
	        }
	    }
}

It's not a bad things to disable minifyEnabled ? Android Console will warned me about that no?

Ok so, I've tried to update the "proguard-rules.pro" file like this (and it works!):

-keep class com.lufinkey.react.spotify.RNSpotifyPackage.** { *; }
-keep class com.lufinkey.react.spotify.** { *; }
-keep class com.spotify.sdk.android.authentication.RNSpotifyPackage.** { *; }
-keep class com.spotify.sdk.android.player.SpotifyPlayer.** { *; }
-keep class com.spotify.sdk.android.player.** { *; }

I don't know how to modify this rule on app's proguard-rules.pro (clearly I'm new on React Native development), maybe making a note/add troubleshooting in the readme is better ?

On real device with intern test on Android, App is crashing :

java.lang.RuntimeException: 
  at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:193)
  at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:21)
  at com.facebook.react.bridge.queue.NativeRunnable.run (NativeRunnable.java)
  at android.os.Handler.handleCallback (Handler.java:873)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java)
  at android.os.Looper.loop (Looper.java:201)
  at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:37)
  at java.lang.Thread.run (Thread.java:764)

Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Method.invoke (Method.java)
  at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:149)
  at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:21)
  at com.facebook.react.bridge.queue.NativeRunnable.run (NativeRunnable.java)
  at android.os.Handler.handleCallback (Handler.java:873)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java)
  at android.os.Looper.loop (Looper.java:201)
  at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:37)
  at java.lang.Thread.run (Thread.java:764)

Caused by: java.lang.UnsatisfiedLinkError: 
  at java.lang.Runtime.loadLibrary0 (Runtime.java:1012)
  at java.lang.System.loadLibrary (System.java:1669)
  at com.spotify.sdk.android.player.SpotifyPlayer.nativeInit (SpotifyPlayer.java:2)
  at com.spotify.sdk.android.player.SpotifyPlayer.<clinit> (SpotifyPlayer.java)
  at com.spotify.sdk.android.player.SpotifyPlayer.access$000 (SpotifyPlayer.java)
  at com.spotify.sdk.android.player.SpotifyPlayer$Builder.build (SpotifyPlayer.java:11)
  at com.spotify.sdk.android.player.Spotify.getPlayer (Spotify.java:11)
  at com.lufinkey.react.spotify.RNSpotifyModule.initializePlayerIfNeeded (RNSpotifyModule.java:94)
  at com.lufinkey.react.spotify.RNSpotifyModule.loginWithSession (RNSpotifyModule.java:20)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:149)
  at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:21)
  at com.facebook.react.bridge.queue.NativeRunnable.run (NativeRunnable.java)
  at android.os.Handler.handleCallback (Handler.java:873)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java)
  at android.os.Looper.loop (Looper.java:201)
  at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:37)
  at java.lang.Thread.run (Thread.java:764)

Is this after you've disabled proguard completely?

Not completely, I just activate proguard and put the rules I wrote right upon