Android Wear Tile JavaBinder 异常

Android Wear Tile JavaBinder Exception

我正在尝试向我的应用添加 Wear OS 磁贴。我没有在 activity 中预览我的图块,因为已经可以添加自定义图块。但是每当我滑动到我的图块时,我都会遇到这个异常,并且图块只显示清单中提供的我的图块标签。

E/JavaBinder: *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
    java.lang.BootstrapMethodError: Exception from call site #29 bootstrap method
        at androidx.wear.tiles.TileEnterEventData.<clinit>(TileEnterEventData.java:32)
        at androidx.wear.tiles.TileProvider$Stub.onTransact(TileProvider.java:197)
        at android.os.Binder.execTransact(Binder.java:731)
     Caused by: java.lang.ClassCastException: Bootstrap method returned null
        at androidx.wear.tiles.TileEnterEventData.<clinit>(TileEnterEventData.java:32) 
        at androidx.wear.tiles.TileProvider$Stub.onTransact(TileProvider.java:197) 
        at android.os.Binder.execTransact(Binder.java:731) 
E/AndroidRuntime: FATAL EXCEPTION: Binder:16030_2
    Process: com.pezcraft.myapplication, PID: 16030
    java.lang.BootstrapMethodError: Exception from call site #29 bootstrap method
        at androidx.wear.tiles.TileEnterEventData.<clinit>(TileEnterEventData.java:32)
        at androidx.wear.tiles.TileProvider$Stub.onTransact(TileProvider.java:197)
        at android.os.Binder.execTransact(Binder.java:731)
     Caused by: java.lang.ClassCastException: Bootstrap method returned null
        at androidx.wear.tiles.TileEnterEventData.<clinit>(TileEnterEventData.java:32) 
        at androidx.wear.tiles.TileProvider$Stub.onTransact(TileProvider.java:197) 
        at android.os.Binder.execTransact(Binder.java:731) 

我的清单看起来像这样...

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pezcraft.heartrateonstream">

    <uses-permission android:name="android.permission.BODY_SENSORS" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

    <uses-feature android:name="android.hardware.type.watch" />
    <uses-feature android:name="android.hardware.sensor.heartrate" />

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar"
        android:allowBackup="false">

        <meta-data
            android:name="com.google.android.wearable.standalone"
            android:value="false" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:taskAffinity=""
            android:excludeFromRecents="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service
            android:name=".HeartRateTileService"
            android:exported="true"
            android:label="@string/tile_label"
            android:description="@string/tile_description"
            android:icon="@drawable/ic_heart"
            android:permission="com.google.android.wearable.permission.BIND_TILE_PROVIDER">
            <intent-filter>
                <action android:name="androidx.wear.tiles.action.BIND_TILE_PROVIDER" />
            </intent-filter>

            <meta-data
                android:name="androidx.wear.tiles.PREVIEW"
                android:resource="@drawable/ic_heart" />
        </service>

    </application>
</manifest>

我的 TileService...

public class HeartRateTileService extends TileService {
    private static final String RESOURCES_VERSION = "1";

    @NonNull
    @Override
    protected ListenableFuture<TileBuilders.Tile> onTileRequest(
            @NonNull RequestBuilders.TileRequest requestParams
    ) {
        return Futures.immediateFuture(new TileBuilders.Tile.Builder()
                .setResourcesVersion(RESOURCES_VERSION)
                .setFreshnessIntervalMillis(1000)
                .setTimeline(new TimelineBuilders.Timeline.Builder()
                        .addTimelineEntry(new TimelineBuilders.TimelineEntry.Builder()
                                .setLayout(new LayoutElementBuilders.Layout.Builder()
                                        .setRoot(
                                                layout()
                                        ).build()
                                ).build()
                        ).build()
                ).build()
        );
    }

    private LayoutElementBuilders.LayoutElement layout() {
        return new LayoutElementBuilders.Row.Builder()
                .setWidth(wrap())
                .setHeight(expand())
                .setVerticalAlignment(LayoutElementBuilders.VERTICAL_ALIGN_BOTTOM)
                .addContent(new LayoutElementBuilders.Text.Builder()
                        .setText("Hello world")
                        .build()
                ).build();
    }

    @NonNull
    @Override
    protected ListenableFuture<ResourceBuilders.Resources> onResourcesRequest(
            @NonNull RequestBuilders.ResourcesRequest requestParams
    ) {
        return Futures.immediateFuture(new ResourceBuilders.Resources.Builder()
                .setVersion(RESOURCES_VERSION)
                .build()
        );
    }

}

我做错了什么?

我用这个问题解决了我的问题...

我已将此添加到我的 build.gradle

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

我不知道为什么需要它,但它现在可以用了。也许有人可以对此解决方案提供更多解释。