Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android crashing in production: java.lang.IllegalStateException #238

Open
joncursi opened this issue Nov 15, 2017 · 33 comments
Open

Android crashing in production: java.lang.IllegalStateException #238

joncursi opened this issue Nov 15, 2017 · 33 comments

Comments

@joncursi
Copy link

I just recently launched my React Native Android app into production and several users are experiencing the following crash:

java.lang.IllegalStateException

screen shot 2017-11-15 at 7 20 04 am

It seems to be coming from the react-native-youtube module. I'm not sure how to go about debugging this. I can't seem to reproduce it locally on any of my physical devices, and because it's Java and not JavaScript, I'm a bit unfamiliar.

If you could help point me in the right direction, I would really appreciate it!

@Jainesh219
Copy link

screen shot 2017-11-24 at 11 37 57 am

App crashes when I slowly scroll down ListView and then slowly try to scroll upto the video and again scroll down to the video.

Logcat show the following error :
java.lang.IllegalStateException: This YouTubePlayer has been released

Help'll be appreciated.

@adamonkey
Copy link

+1

@banphlet
Copy link

banphlet commented Feb 2, 2018

i have the same issue

 java.lang.IllegalStateException: This YouTubePlayer has been released

@saitbnzl
Copy link

saitbnzl commented Feb 23, 2018

+1 In my case, the crash is happening when I go to Youtube by tapping the Youtube button and then come back to my app.

@ozanmanav
Copy link

ozanmanav commented Feb 23, 2018

Same +1

@shubz1998
Copy link

Same Error with me.
Has anyone found the solution ?

@judemanutd
Copy link

Same here

@ed828a
Copy link

ed828a commented Jun 6, 2018

I got the same problem when I rotated the phone

@mehulmpt
Copy link

mehulmpt commented Sep 9, 2018

Is there any update on this? It still happens on my production app.

@emil-ep
Copy link

emil-ep commented Oct 4, 2018

Same issue here. Any fixes?

@Kisepro
Copy link

Kisepro commented Dec 2, 2018

Same ...

@vkumarNobul
Copy link

+1

@adamvenord17
Copy link

adamvenord17 commented Mar 1, 2019

    --------- beginning of crash
2019-03-01 11:23:23.427 6523-6523/com.allsocial.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.allsocial.app, PID: 6523
    java.lang.IllegalStateException: This YouTubePlayer has been released
        at hue.a(SourceFile:98)
        at hue.l(SourceFile:227)
        at acye.onTransact(SourceFile:54)
        at android.os.Binder.transact(Binder.java:604)
        at com.google.android.youtube.player.internal.d$a$a.a(Unknown Source:18)
        at com.google.android.youtube.player.internal.s.play(Unknown Source:2)
        at com.inprogress.reactnativeyoutube.YouTubePlayerController$1.run(YouTubePlayerController.java:315)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    
    
    --------- beginning of system

@HashDot
Copy link

HashDot commented Mar 20, 2019

You can set "resumePlayAndroid" to false to prevent the app to crash. The problem with this solution is, you get a black rectangle instead of a crash.

Here a gist how I solved the problem with "This YouTubePlayer has been released" and Black Screen.

https://gist.github.com/HashDot/e47ad8366d9193901c9c7538276874a2

@Khuongnb
Copy link

Khuongnb commented Jun 19, 2019

@HashDot What version of react-native-youtube are you using? I'm using v1.1.0 and it doesn't work.
Work around using YoutubeStandaloneAndroid but it affects a lot of tracking algorithm since your app state change to "background" on play and "active" when it stop.

@HashDot
Copy link

HashDot commented Jun 19, 2019

@Khuongnb I use v1.1.0
You can find a more detailed explanation on my blog: https://hashdot.co/blog/react-native-youtube but I need to update the post with some more dirty tricks how I get what I want :D

@lefrankleal
Copy link

You can set "resumePlayAndroid" to false to prevent the app to crash. The problem with this solution is, you get a black rectangle instead of a crash.

Here a gist how I solved the problem with "This YouTubePlayer has been released" and Black Screen.

https://gist.github.com/HashDot/e47ad8366d9193901c9c7538276874a2

this solved my crash problem, but now the video stay as a black space, cant do anything like, play

@HashDot
Copy link

HashDot commented Aug 8, 2019

@lefrankleal check out my blog article: https://hashdot.co/blog/react-native-youtube

@neneji
Copy link

neneji commented Sep 4, 2019

@lefrankleal check out my blog article: https://hashdot.co/blog/react-native-youtube

hi @HashDot, i followed your tutorial, but once i come back to the previous screen, the video played for 1 sec then stop, UNAUTHORIZED_OVERLAY error :(
any ideas?

@code-jenn-or
Copy link

I also attempted to follow @HashDot tutorial but now it will play for 1second and then stop. It does not crash but it doesn't work either. Has any solved this? If not looks like I'll be using another video player.

@bbeckkk
Copy link

bbeckkk commented Mar 14, 2020

Theres a youtube button that'll open separate youtube app. If youtube app is closed, the app crashes. None of the above solution worked for me.
See the details here

@GnApollo
Copy link

You can just tweak it with state. have a initial state of loading true, then

componentWillUnmount() {
// Remove the event listener
this.focusListener();
}

componentDidMount = () => {
   // every time the screen is focus
    this.focusListener = this.props.navigation.addListener('focus', () => {
        this.setState({ loading: true })
        setTimeout(() => {
            this.setState({ loading: false })
        }, 100);
    })
};

in your render function just dont render the YoutubePlayer if the state is loading.

if you want to navigate to other screen just setState({ loading : true}, () => //navigate )

@psdewar
Copy link

psdewar commented Aug 21, 2020

@samulon13 is the loading state you mentioned associated with rendering the component like so?

{!isLoading && <Youtube ... />}

This crashes for me. What are you returning?

@GnApollo
Copy link

{this.state.loading ? : <Youtube ... />}

@GnApollo
Copy link

i also use Backhandler and set the loading to true again when ever the system go back. Because in application the number of navigation to push depends on the number of nodes that was created by the admin.

darriuk added a commit to darriuk/react-native-youtube that referenced this issue Sep 15, 2020
Bugfix for issue davidohayon669#312 & davidohayon669#238: "Unable to instantiate fragment..."
@chichilatte
Copy link

We had this trouble and fixed it by tweaking android/src/main/java/com/inprogress/reactnativeyoutube/VideoFragment.java. More info here.

Also, to replicate the crash – on the device/simulator i would be on our app, then switch to a memory-hungry webpage that ate up 100s of megs and then switch back to our app.

@sangameshrently
Copy link

I solved like this

<YouTube
key = {Math.random()}

@92sajid110
Copy link

I also attempted to follow @HashDot tutorial but now it will play for 1second and then stop. It does not crash but it doesn't work either. Has any solved this? If not looks like I'll be using another video player.

yes same for me any help or update how you solved

@92sajid110
Copy link

I solved like this

<YouTube
key = {Math.random()}

didn't work unauthorized overlay

@kongen84
Copy link

I still get this error.

The error almost never occurs in debug mode. It occurs more often when attached to the metro serverwith debug off, It occurs a lot of the time in production builds, virtually always on first load.

Setting resumePlayAndroid to false results in a black screen instead of a crash. This is a little better but not much.

@kongen84
Copy link

Work around using YoutubeStandaloneAndroid

That doesn't work for me either. The app crashes frequently and always on the first run.

@sergiulucaci
Copy link

sergiulucaci commented Oct 15, 2021

You can just tweak it with state. have a initial state of loading true, then

componentWillUnmount() { // Remove the event listener this.focusListener(); }

componentDidMount = () => {
   // every time the screen is focus
    this.focusListener = this.props.navigation.addListener('focus', () => {
        this.setState({ loading: true })
        setTimeout(() => {
            this.setState({ loading: false })
        }, 100);
    })
};

in your render function just dont render the YoutubePlayer if the state is loading.

if you want to navigate to other screen just setState({ loading : true}, () => //navigate )

This worked for me, thanks.

react-navigation v6

import React, { useCallback, useState } from 'react';
import { useFocusEffect } from '@react-navigation/native';

const VideoPlayer = () => {
  const [shouldDisplayYoutube, setShouldDisplayYoutube] = useState(false);

  useFocusEffect(
    useCallback(() => {
        setTimeout(() => {
            setShouldDisplayYoutube(true);
        }, 100);
        return () => {
            setShouldDisplayYoutube(false);
        };
    }, []),
  );

  return shouldDisplayYoutube &&  <YouTube key={Math.random()} ... />
}

You can add some conditions to make sure this happens on Android only.

@mMarcos208
Copy link

it work for me.

#436 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests