Skip to content

[camera_android_camerax] Fixes premature garbage collection of native objects when app is under memory pressure #9287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.18+2

* Fixes premature garbage collection of native objects when app is under memory pressure.

## 0.6.18+1

* Makes Java style improvements.
Expand Down
142 changes: 71 additions & 71 deletions packages/camera/camera_android_camerax/android/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,125 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.6.0" type="baseline" client="gradle" dependencies="false" name="AGP (8.6.0)" variant="all" version="8.6.0">
<issues format="6" by="lint 8.9.1" type="baseline" client="gradle" dependencies="false" name="AGP (8.9.1)" variant="all" version="8.9.1">

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" else if (value is androidx.camera.camera2.interop.CaptureRequestOptions) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" } else if (value is androidx.camera.camera2.interop.CaptureRequestOptions) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="939"
column="24"/>
line="937"
column="25"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" else if (value is androidx.camera.camera2.interop.Camera2CameraControl) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" } else if (value is androidx.camera.camera2.interop.Camera2CameraControl) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="942"
column="24"/>
line="939"
column="25"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" else if (value is androidx.camera.camera2.interop.Camera2CameraInfo) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" } else if (value is androidx.camera.camera2.interop.Camera2CameraInfo) {"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="954"
column="24"/>
line="947"
column="25"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" abstract fun pigeon_defaultConstructor(options: Map&lt;android.hardware.camera2.CaptureRequest.Key&lt;*>, Any?>): androidx.camera.camera2.interop.CaptureRequestOptions"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" ): androidx.camera.camera2.interop.CaptureRequestOptions"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5555"
column="111"/>
line="6418"
column="6"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" abstract fun getCaptureRequestOption(pigeon_instance: androidx.camera.camera2.interop.CaptureRequestOptions, key: android.hardware.camera2.CaptureRequest.Key&lt;*>): Any?"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" pigeon_instance: androidx.camera.camera2.interop.CaptureRequestOptions,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5561"
column="57"/>
line="6422"
column="24"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" val pigeon_instanceArg = args[0] as androidx.camera.camera2.interop.CaptureRequestOptions"
errorLine1=" val pigeon_instanceArg ="
errorLine2=" ~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5591"
line="6467"
column="17"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" val pigeon_instanceArg = args[0] as androidx.camera.camera2.interop.CaptureRequestOptions"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" args[0] as androidx.camera.camera2.interop.CaptureRequestOptions"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5591"
column="49"/>
line="6468"
column="28"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" fun pigeon_newInstance(pigeon_instanceArg: androidx.camera.camera2.interop.CaptureRequestOptions, callback: (Result&lt;Unit>) -> Unit)"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" pigeon_instanceArg: androidx.camera.camera2.interop.CaptureRequestOptions,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5609"
column="46"/>
line="6488"
column="27"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" abstract fun from(cameraControl: androidx.camera.core.CameraControl): androidx.camera.camera2.interop.Camera2CameraControl"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" ): androidx.camera.camera2.interop.Camera2CameraControl"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5647"
column="73"/>
line="6533"
column="6"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" abstract fun addCaptureRequestOptions(pigeon_instance: androidx.camera.camera2.interop.Camera2CameraControl, bundle: androidx.camera.camera2.interop.CaptureRequestOptions, callback: (Result&lt;Unit>) -> Unit)"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" pigeon_instance: androidx.camera.camera2.interop.Camera2CameraControl,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5653"
column="58"/>
line="6537"
column="24"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" abstract fun addCaptureRequestOptions(pigeon_instance: androidx.camera.camera2.interop.Camera2CameraControl, bundle: androidx.camera.camera2.interop.CaptureRequestOptions, callback: (Result&lt;Unit>) -> Unit)"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" bundle: androidx.camera.camera2.interop.CaptureRequestOptions,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5653"
column="120"/>
line="6538"
column="15"/>
</issue>

<issue
Expand All @@ -129,7 +129,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5683"
line="6583"
column="17"/>
</issue>

Expand All @@ -140,7 +140,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5683"
line="6583"
column="49"/>
</issue>

Expand All @@ -151,7 +151,7 @@
errorLine2=" ~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5684"
line="6584"
column="17"/>
</issue>

Expand All @@ -162,52 +162,52 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5684"
line="6584"
column="40"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" fun pigeon_newInstance(pigeon_instanceArg: androidx.camera.camera2.interop.Camera2CameraControl, callback: (Result&lt;Unit>) -> Unit)"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" pigeon_instanceArg: androidx.camera.camera2.interop.Camera2CameraControl,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5703"
column="46"/>
line="6604"
column="27"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" abstract fun from(cameraInfo: androidx.camera.core.CameraInfo): androidx.camera.camera2.interop.Camera2CameraInfo"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" ): androidx.camera.camera2.interop.Camera2CameraInfo"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5946"
column="67"/>
line="6899"
column="6"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" abstract fun getCameraId(pigeon_instance: androidx.camera.camera2.interop.Camera2CameraInfo): String"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" pigeon_instance: androidx.camera.camera2.interop.Camera2CameraInfo"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5949"
column="45"/>
line="6903"
column="24"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" abstract fun getCameraCharacteristic(pigeon_instance: androidx.camera.camera2.interop.Camera2CameraInfo, key: android.hardware.camera2.CameraCharacteristics.Key&lt;*>): Any?"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" pigeon_instance: androidx.camera.camera2.interop.Camera2CameraInfo,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5952"
column="57"/>
line="6908"
column="24"/>
</issue>

<issue
Expand All @@ -217,7 +217,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5982"
line="6950"
column="17"/>
</issue>

Expand All @@ -228,7 +228,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5982"
line="6950"
column="49"/>
</issue>

Expand All @@ -239,7 +239,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5999"
line="6972"
column="17"/>
</issue>

Expand All @@ -250,19 +250,19 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="5999"
line="6972"
column="49"/>
</issue>

<issue
id="UnsafeOptInUsageError"
message="This declaration is opt-in and its usage should be marked with `@androidx.camera.camera2.interop.ExperimentalCamera2Interop` or `@OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)`"
errorLine1=" fun pigeon_newInstance(pigeon_instanceArg: androidx.camera.camera2.interop.Camera2CameraInfo, callback: (Result&lt;Unit>) -> Unit)"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" pigeon_instanceArg: androidx.camera.camera2.interop.Camera2CameraInfo,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt"
line="6017"
column="46"/>
line="6992"
column="27"/>
</issue>

</issues>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v25.3.1), do not edit directly.
// Autogenerated from Pigeon (v25.3.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")

Expand Down Expand Up @@ -3643,7 +3643,7 @@ abstract class PigeonApiVideoRecordEventListener(
abstract class PigeonApiPendingRecording(
open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
) {
/** Enables audio to be recorded for this recording. */
/** Enables/disables audio to be recorded for this recording. */
abstract fun withAudioEnabled(
pigeon_instance: androidx.camera.video.PendingRecording,
initialMuted: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void onFailure(@NonNull String methodName, @NonNull Throwable throwable) {
}

// PreviewProxyApi maintains a state to track SurfaceProducers provided by the Flutter engine.
@NonNull private final PreviewProxyApi previewProxyApi = new PreviewProxyApi(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm what version of Java are you using with locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried building again on flutter stable and I don't get the lint error. Could it be caused by the flutter.compileSdkVersion in the example app build.gradle? I was building it on flutter main before. Regardless, the lint seems to be valid.

@Nullable private PreviewProxyApi previewProxyApi;

public ProxyApiRegistrar(
@NonNull BinaryMessenger binaryMessenger,
Expand Down Expand Up @@ -221,6 +221,9 @@ public DeviceOrientationManagerProxyApi getPigeonApiDeviceOrientationManager() {
@NonNull
@Override
public PigeonApiPreview getPigeonApiPreview() {
if (previewProxyApi == null) {
previewProxyApi = new PreviewProxyApi(this);
}
return previewProxyApi;
}

Expand Down
Loading