2016-08-23 5 views
3

youtube player sdkを使用して約30〜40回再生すると、Youtubeアプリケーションがクラッシュするため、リモートプロセスが終了してDeadObjectExceptionが発生します。再現手順:OutOfMemoryErrorはYouTubeのAndroidプレーヤーのAPIを使用して発生します。1.2.2

  1. 発射活動をして初期化YouTubePlayer
  2. 負荷と数秒間のビデオを再生
  3. リリースYouTubePlayerと出口活動
  4. 繰り返しステップ1-3の約30〜40倍

のOutOfMemoryErrorログ(full logs):

08-22 12:01:01.461 E/AndroidRuntime(3017): FATAL EXCEPTION: main 
08-22 12:01:01.461 E/AndroidRuntime(3017): Process: com.google.android.youtube.player, PID: 3017 
08-22 12:01:01.461 E/AndroidRuntime(3017): java.lang.OutOfMemoryError: Could not allocate JNI Env 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at java.lang.Thread.nativeCreate(Native Method) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at java.lang.Thread.start(Thread.java:1063) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:921) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1556) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:310) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:527) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:616) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at reo.a(SourceFile:134) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at sgh.a(SourceFile:722) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at gan.a(SourceFile:310) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at gan.b(SourceFile:338) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerService$2.run(SourceFile:215) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at android.os.Handler.handleCallback(Handler.java:739) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at android.os.Handler.dispatchMessage(Handler.java:95) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at android.os.Looper.loop(Looper.java:148) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at android.app.ActivityThread.main(ActivityThread.java:5417) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at java.lang.reflect.Method.invoke(Native Method) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
08-22 12:01:01.461 E/AndroidRuntime(3017):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

とDeadObjectException

08-22 12:01:01.842 E/MonitoringInstrumentation(2976): java.lang.IllegalStateException: android.os.DeadObjectException 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at gix.surfaceCreated(SourceFile:189) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.SurfaceView.updateWindow(SurfaceView.java:582) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:177) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2055) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.Choreographer.doCallbacks(Choreographer.java:670) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.Choreographer.doFrame(Choreographer.java:606) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.os.Handler.handleCallback(Handler.java:739) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.os.Handler.dispatchMessage(Handler.java:95) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.os.Looper.loop(Looper.java:148) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.app.ActivityThread.main(ActivityThread.java:5417) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at java.lang.reflect.Method.invoke(Native Method) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): Caused by: android.os.DeadObjectException 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.os.BinderProxy.transactNative(Native Method) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at android.os.BinderProxy.transact(Binder.java:503) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ISurfaceHolderService$Stub$Proxy.a(SourceFile:110) 
08-22 12:01:01.842 E/MonitoringInstrumentation(2976): at gix.surfaceCreated(SourceFile:186) 

のYouTubeアプリのバージョンは11.29.55、マシュマロ とNexus 5のエミュレータです、私は10.25.57と10.40.58のようなYouTubeのアプリケーションの他のバージョンでそれをテストしてみた、OOMが引き続き発生します。

私がこの問題に遭遇したとき、私はそれがちょうど間違ったAPIメソッド呼び出しによって引き起こされたと思っていましたが、何時間もの研究の結果、YouTube Appの問題であるはずです。少なくともそれを避けてください。

プレイヤーの初期化とビデオの再生中にプロセスcom.google.android.youtube.playerのメモリが増加しており、多くのYoutubeServiceインスタンスがダンプファイルから作成されましたがリサイクルされませんでした。何か案が?

も、私はテストコードを追加して、私は、自動演奏のためにPlayerViewDemoActivityloadVideo(String)cueVideo(String)を置き換え、そしてonDestroy()YouTubePlayer#release()を追加し、私は公式YouTubeAndroidAPIサンプルに基づいてデモアプリケーションでそれをテストしにOutOfMemoryエラーが同様に発生しますエスプレッソに基づいてメモリリークの問題を再現します。

ここにテストコードがあり、完全なデモコードはhereです。

package com.examples.youtubeapidemo.play; 

import android.os.SystemClock; 
import android.support.test.rule.ActivityTestRule; 
import android.support.test.runner.AndroidJUnit4; 
import android.test.suitebuilder.annotation.LargeTest; 
import android.util.Log; 

import com.examples.youtubeapidemo.YouTubeAPIDemoActivity; 

import org.junit.Rule; 
import org.junit.Test; 
import org.junit.runner.RunWith; 

import static android.support.test.espresso.Espresso.onView; 
import static android.support.test.espresso.Espresso.pressBack; 
import static android.support.test.espresso.action.ViewActions.click; 
import static android.support.test.espresso.matcher.ViewMatchers.withText; 

/** 
* for YouTubePlayerView testing 
*/ 
@RunWith(AndroidJUnit4.class) 
@LargeTest 
public class PlayerViewTest { 

    @Rule 
    public ActivityTestRule<YouTubeAPIDemoActivity> mActivityTestRule = 
      new ActivityTestRule<YouTubeAPIDemoActivity>(YouTubeAPIDemoActivity.class); 

    @Test 
    public void testYouTubeMemoryLeaks() { 
     int count = 0; 
     while(count < 100) { 
      onView(withText("Simple PlayerView")).perform(click()); 
      SystemClock.sleep(10000); // waiting for video start playing 
      pressBack(); 
      count++; 
      Log.i("PlayerViewTest", "count: " + count); 
     } 
    } 
} 
+0

あなたがこのための修正を見つけましたか?私は今、私のアプリでそれを実装しようとしているとは、巨大なメモリリークを引き起こし、インスタンスを解放することはありません。 –

+1

@Drew汚れた回避策を見つけましたが、うまくいきますが、誰もそれを実装することを決して勧めません。私は 'com.google.android.youtube'プロセスが' android.permission.KILL_BACKGROUND_PROCESSES'アクセス権を必要とする 'activityManager.killBackgroundProcesses(" com.google.android.youtube ");'によって手動で終了することに気付きました。 youtube playerインスタンスがリリースされました。 –

+1

私の実装は、10人のYouTubeプレーヤーの初期化のたびにプロセスを強制終了します。うまく動作し、テストに合格しましたが、他のプロセスを手動で強制終了するのは間違いです。また、crash statsプラットフォームからクラッシュ統計をチェックしたところ、OOMクラッシュに直面したユーザーはほとんどいないことがわかりました(1週間あたり1〜2回、毎日のアクティブユーザー50,000人と比較して、アプリのデザイン、 30以上のvids以上のブラウザに忍耐がある)、それを無視することにしました。 –

答えて

0

私は、try catchブロックで(youtubePlayer.loadVideo()、cueVideo()のような、getCurrentTimeMillis()など)を呼び出すユーチューブを置くことによって、バグの発生を低減し、IllegalStateExceptionが例外が、その後ユーチューブプレーヤーを再初期化キャッチ。

及びこれらの例外をキャッチすることにより、その周りに働いて、活動を再開し、

は、このスレッドで私の答えを参照してください。 Getting a lot of crashes from android youtube player api

関連する問題