diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java b/shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java index 05a3bdafb0c8c..64711d66cf26f 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java @@ -8,12 +8,12 @@ import androidx.annotation.Keep; import androidx.annotation.NonNull; +@Keep public class FlutterOverlaySurface { @NonNull private final Surface surface; private final long id; - @Keep public FlutterOverlaySurface(long id, @NonNull Surface surface) { this.id = id; this.surface = surface; diff --git a/shell/platform/android/platform_view_android_jni_impl.cc b/shell/platform/android/platform_view_android_jni_impl.cc index 8f874ebdfe7fe..cebb2ecb02e18 100644 --- a/shell/platform/android/platform_view_android_jni_impl.cc +++ b/shell/platform/android/platform_view_android_jni_impl.cc @@ -102,9 +102,9 @@ static jmethodID g_on_display_platform_view_method = nullptr; static jmethodID g_on_display_overlay_surface_method = nullptr; -static jfieldID g_overlay_surface_id_field = nullptr; +static jmethodID g_overlay_surface_id_method = nullptr; -static jfieldID g_overlay_surface_surface_field = nullptr; +static jmethodID g_overlay_surface_surface_method = nullptr; // Called By Java static jlong AttachJNI(JNIEnv* env, @@ -708,16 +708,17 @@ bool RegisterApi(JNIEnv* env) { FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface class"; return false; } - g_overlay_surface_id_field = - env->GetFieldID(overlay_surface_class.obj(), "id", "J"); - if (g_overlay_surface_id_field == nullptr) { - FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.id field"; + g_overlay_surface_id_method = + env->GetMethodID(overlay_surface_class.obj(), "getId", "()J"); + if (g_overlay_surface_id_method == nullptr) { + FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface#getId() method"; return false; } - g_overlay_surface_surface_field = env->GetFieldID( - overlay_surface_class.obj(), "surface", "Landroid/view/Surface;"); - if (g_overlay_surface_surface_field == nullptr) { - FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.surface field"; + g_overlay_surface_surface_method = env->GetMethodID( + overlay_surface_class.obj(), "getSurface", "()Landroid/view/Surface;"); + if (g_overlay_surface_surface_method == nullptr) { + FML_LOG(ERROR) + << "Could not locate FlutterOverlaySurface#getSurface() method"; return false; } @@ -1147,13 +1148,13 @@ PlatformViewAndroidJNIImpl::FlutterViewCreateOverlaySurface() { } jlong overlay_id = - env->GetLongField(overlay.obj(), g_overlay_surface_id_field); + env->CallLongMethod(overlay.obj(), g_overlay_surface_id_method); - fml::jni::ScopedJavaLocalRef overlay_surface( - env, env->GetObjectField(overlay.obj(), g_overlay_surface_surface_field)); + jobject overlay_surface = + env->CallObjectMethod(overlay.obj(), g_overlay_surface_surface_method); auto overlay_window = fml::MakeRefCounted( - ANativeWindow_fromSurface(env, overlay_surface.obj())); + ANativeWindow_fromSurface(env, overlay_surface)); return std::make_unique( overlay_id, std::move(overlay_window));