lufinkey / react-native-spotify

A react native module for the Spotify SDK. [Deprecated]
378 stars 76 forks source link

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

Open Mobuis opened 5 years ago

Mobuis commented 5 years ago

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

lufinkey commented 5 years ago

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?

lufinkey commented 5 years ago

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

Mobuis commented 5 years ago

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 ?

lufinkey commented 5 years ago

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

Mobuis commented 5 years ago

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

lufinkey commented 5 years ago

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

Mobuis commented 5 years ago

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 !

Mobuis commented 5 years ago

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

lufinkey commented 5 years ago

From the app's gradle file or the react native module's gradle file?

On Thu, Sep 19, 2019, 2:40 PM Nolane notifications@github.com wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lufinkey/react-native-spotify/issues/143?email_source=notifications&email_token=AB3VGUN5RKHXYVELLO54PXLQKPBRFA5CNFSM4IYMAYM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7EN5GI#issuecomment-533257881, or mute the thread https://github.com/notifications/unsubscribe-auth/AB3VGUMAHJDYB2CF6AZHKMDQKPBRFANCNFSM4IYMAYMQ .

Mobuis commented 5 years ago

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
            }
        }
}
Mobuis commented 5 years ago

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

Mobuis commented 5 years ago

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.** { *; }
lufinkey commented 5 years ago

Would you be open to making a PR?

On Thu, Sep 19, 2019, 4:19 PM Nolane notifications@github.com wrote:

Ok so, I've tried to update the proguard rule 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.* { ; }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lufinkey/react-native-spotify/issues/143?email_source=notifications&email_token=AB3VGUKQNBUTTH6ZZ7R3IVTQKPNEZA5CNFSM4IYMAYM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7EWSAQ#issuecomment-533293314, or mute the thread https://github.com/notifications/unsubscribe-auth/AB3VGUIRUCFOHMYOJ47UPYLQKPNEZANCNFSM4IYMAYMQ .

Mobuis commented 5 years ago

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 ?

Mobuis commented 5 years ago

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)
lufinkey commented 5 years ago

Is this after you've disabled proguard completely?

Mobuis commented 5 years ago

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