警告:无法在类型'OnLifecycleEvent'中找到注释方法'value()':找不到android.arch.lifecycle.OnLifecycleEvent的类文件

时间:2018-07-19 10:23:38

标签: java android reactjs react-native viewgroup

我正在为本地反应做一个android bridge, 以下模块之一:https://github.com/PierfrancescoSoffritti/android-youtube-player/

但出现以下错误:

warning: Cannot find annotation method 'value()' in type 'OnLifecycleEvent': class file for android.arch.lifecycle.OnLifecycleEvent not found

warning: unknown enum constant Event.ON_DESTROY reason: class file for android.arch.lifecycle.Lifecycle not found

warning: Cannot find annotation method 'value()' in type 'OnLifecycleEvent'

warning: unknown enum constant Event.ON_STOP

error: cannot access LifecycleObserver
        youtubePlayerView.initialize(new YouTubePlayerInitListener() {
                         ^
  class file for android.arch.lifecycle.LifecycleObserver not found

这是我正在使用的源代码,我无法扩展AppCompatActivity来使用 getLifecycle()。addObserver(youtubePlayerView);

package com.uiyoutube;

import android.support.annotation.NonNull;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewGroupManager;
import com.pierfrancescosoffritti.androidyoutubeplayer.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.player.YouTubePlayerView;
import com.pierfrancescosoffritti.androidyoutubeplayer.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.player.listeners.YouTubePlayerInitListener;

public class RNMaterialLetterIcon extends ViewGroupManager<ViewGroup> {

    public static final String REACT_CLASS = "RNMaterialLetterIcon";

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    @Override
    protected FrameLayout createViewInstance(final ThemedReactContext reactContext) {
        //int randomId;

        //Random rand = new Random();
        //while (reactContext.getCurrentActivity().findViewById(randomId = rand.nextInt(Integer.MAX_VALUE) + 1) != null)
        ;
        //final int viewId = randomId;

        YouTubePlayerView youtubePlayerView = new YouTubePlayerView(reactContext);
        //youtubePlayerView.getPlayerUIController().showVideoTitle(true);
        //youtubePlayerView.getPlayerUIController().showYouTubeButton(false);
        //youtubePlayerView.getPlayerUIController().showFullscreenButton(false);

        //AppCompatActivity.getLifecycle().addObserver(youtubePlayerView);

        youtubePlayerView.initialize(new YouTubePlayerInitListener() {
            String videoId = "vs0-ix6UhwU";

            @Override
            public void onInitSuccess(@NonNull final YouTubePlayer initializedYouTubePlayer) {
                initializedYouTubePlayer.addListener(new AbstractYouTubePlayerListener() {
                    @Override
                    public void onReady() {
                        initializedYouTubePlayer.loadVideo(videoId, 660);
                    }

                    @Override
                    public void onCurrentSecond(float second) {
                        if (second == 680) initializedYouTubePlayer.seekTo(660);
                    }
                });
            }
        }, true);

        final FrameLayout frameLayout = new FrameLayout(reactContext);
        frameLayout.addView(youtubePlayerView);

        return frameLayout;
    }

}

我该如何解决?

1 个答案:

答案 0 :(得分:0)

您可能需要导入lifecycle library或appcompat。 之所以抱怨,是因为它不了解生命周期库中的内容。