Android:在发布版本中未检测到Cast SDK v3 CastOptionsProvider

时间:2016-10-08 18:24:15

标签: android casting chromecast

我已正确宣布CastOptiponsProvider manifest.xml

        <meta-data
        android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
        android:value="org.lao.yao.kd.cast.CastOptionsProvider" />

无论如何,只有在我构建app for release时才会出现此错误消息:

java.lang.ClassNotFoundException: org.lao.yao.kd.cast.CastOptionsProvider

这是我的CastOptionsProvider类:

public class CastOptionsProvider implements OptionsProvider {

@Override
public CastOptions getCastOptions(Context context) {
    NotificationOptions notificationOptions = new NotificationOptions.Builder()
            .setActions(Arrays.asList(MediaIntentReceiver.ACTION_SKIP_NEXT,
                    MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK,
                    MediaIntentReceiver.ACTION_STOP_CASTING), new int[]{1, 2})
            .setTargetActivityClassName(ExpandedControlsActivity.class.getName())
            .build();
    CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
            .setImagePicker(new ImagePickerImpl())
            .setNotificationOptions(notificationOptions)
            .setExpandedControllerActivityClassName(ExpandedControlsActivity.class.getName())
            .build();
    return new CastOptions.Builder()
            .setReceiverApplicationId(MyJsonConfig.getPrefString(MyJsonConfig.KEY_CHROMECAST_RECEIVER_ID, context) )
            .setCastMediaOptions(mediaOptions)
            .build();
}

@Override
public List<SessionProvider> getAdditionalSessionProviders(Context appContext) {
    return null;
}

private static class ImagePickerImpl extends ImagePicker {

    @Override
    public WebImage onPickImage(MediaMetadata mediaMetadata, int type) {
        if ((mediaMetadata == null) || !mediaMetadata.hasImages()) {
            return null;
        }
        List<WebImage> images = mediaMetadata.getImages();
        if (images.size() == 1) {
            return images.get(0);
        } else {
            if (type == ImagePicker.IMAGE_TYPE_MEDIA_ROUTE_CONTROLLER_DIALOG_BACKGROUND) {
                return images.get(0);
            } else {
                return images.get(1);
            }
        }
    }
}

}

我还使用proguard进行发布构建。

1 个答案:

答案 0 :(得分:6)

我在使用Proguard和外部库(特别是谷歌的东西)之前遇到过这个问题。我在proguard-rules.pro文件中使用了以下内容:

-keep class org.lao.yao.kd.cast.CastOptionsProvider { *; }

您的CastIntentReceiver。

-keep class org.lao.yao.kd.cast.CastIntentReceiver { *; }

为了更好的衡量,我还添加了以下几行:

-keep class android.support.** { *; }
-keep class com.google.** { *; }
-keep class java.nio.file.** { *; }