Skip to content

Commit 538239f

Browse files
authored
[camera_android_camerax] Add explicit concurrent-futures dependency (flutter#12373)
`camera_android_camerax`'s Gradle module does not explicitly declare a dependency on `androidx.concurrent:concurrent-futures`. Verified via `androidx.camera:camera-core:1.6.1`'s own Gradle module metadata (`.module` file): `camera-core` declares `androidx.concurrent:concurrent-futures` only on its **runtime** variant (`releaseVariantReleaseRuntimePublication`), not its **api/compile** variant (`releaseVariantReleaseApiPublication`). So when a consumer compiles against `camera-core`, Gradle correctly does not put `concurrent-futures` on the compile classpath — that's not a resolution bug, it's what `camera-core`'s own metadata declares. However, `camera-core`'s compiled `SurfaceRequest.class` carries a compile-time-retained jspecify `@NonNull` type annotation on a member typed `androidx.concurrent.futures.CallbackToFutureAdapter`. javac needs that class on the compile classpath to fully process the annotation metadata during compilation — even though no `camera_android_camerax` (or `camera-core`) source calls it directly. This is a mismatch in `camera-core`'s own packaging (a type needed at compile time for annotation processing, but declared runtime-only), which the Flutter team can't fix upstream since `camera-core` is owned by the AndroidX/Jetpack team. Declaring the dependency explicitly in `camera_android_camerax` works around it. Confirmed 100% reproducible on a completely stock, uncustomized `flutter create` app on current stable (3.44.8, default AGP 9.0.1, compileSdk 37): ``` flutter create camera_repro cd camera_repro flutter pub add camera flutter build apk --debug ``` fails every time with: ``` error: Cannot attach type annotations @org.jspecify.annotations.NonNull to SurfaceRequest.mSurfaceRecreationCompleter: class file for androidx.concurrent.futures.CallbackToFutureAdapter not found ``` Minimal repro repo (steps + README with root cause): https://github.com/dhc-tech/camera-android-camerax-build-repro List which issues are fixed by this PR: Fixes flutter#190505 ## Pre-Review Checklist
1 parent ed5bd29 commit 538239f

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎packages/camera/camera_android_camerax/CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.7.4+6
2+
3+
* Adds explicit `androidx.concurrent:concurrent-futures:1.2.0` dependency to fix
4+
`compileDebugJavaWithJavac` failing with "class file for
5+
androidx.concurrent.futures.CallbackToFutureAdapter not found" when
6+
`camera-core`'s Jspecify type annotations are resolved during compilation.
7+
18
## 0.7.4+5
29

310
* Fixes a leaked thread per capture by dispatching the `takePicture` result callback on the main

‎packages/camera/camera_android_camerax/android/build.gradle.kts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ dependencies {
8282
implementation("androidx.camera:camera-lifecycle:${cameraxVersion}")
8383
implementation("androidx.camera:camera-video:${cameraxVersion}")
8484
implementation("com.google.guava:guava:33.5.0-android")
85+
// camera-core's compiled classes reference CallbackToFutureAdapter type annotations;
86+
// without this explicit dependency, javac fails to resolve them during compilation.
87+
// Upstream: https://issuetracker.google.com/issues/543937345
88+
implementation("androidx.concurrent:concurrent-futures:1.2.0")
8589
testImplementation("junit:junit:4.13.2")
8690
testImplementation("org.mockito:mockito-core:5.23.0")
8791
testImplementation("org.mockito:mockito-inline:5.2.0")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.camerax;
6+
7+
import static org.junit.Assert.assertNotNull;
8+
9+
import androidx.concurrent.futures.CallbackToFutureAdapter;
10+
import org.junit.Test;
11+
12+
/**
13+
* Regression test for https://github.com/flutter/flutter/issues/190505.
14+
*
15+
* <p>{@code camera-core}'s compiled classes carry Jspecify {@code @NonNull} type annotations on
16+
* members that reference {@link CallbackToFutureAdapter}. javac needs that class on the compile
17+
* classpath to process those annotations, even though this plugin never calls the annotated members
18+
* directly. Without an explicit {@code androidx.concurrent:concurrent-futures} dependency,
19+
* resolution of that class can silently depend on transitive dependency behavior and fail with
20+
* "class file for androidx.concurrent.futures.CallbackToFutureAdapter not found" during {@code
21+
* compileDebugJavaWithJavac}.
22+
*
23+
* <p>The static reference to {@link CallbackToFutureAdapter} below means that if the explicit
24+
* dependency in {@code android/build.gradle.kts} is ever removed, this test target fails to compile
25+
* instead of the break only surfacing as a build error for consumers.
26+
*/
27+
public class ConcurrentFuturesDependencyTest {
28+
@Test
29+
public void callbackToFutureAdapter_isOnClasspath() {
30+
assertNotNull(CallbackToFutureAdapter.class);
31+
}
32+
}

‎packages/camera/camera_android_camerax/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_android_camerax
22
description: Android implementation of the camera plugin using the CameraX library.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.7.4+5
5+
version: 0.7.4+6
66

77
environment:
88
sdk: ^3.12.0

0 commit comments

Comments
 (0)