googlesamples / googlesamples/mlkit
[Bug report] [Android] Kotlin Delegation is not working with MlKitAnalyzer
- Dominant language
- Kotlin
- Stars
- 4.3k
- Forks
- 3.1k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When Kotlin [delegation](https://kotlinlang.org/docs/delegation.html) is used as following:
````kotlin
class BarcodeScanningAnalyzer internal constructor(
mlKitAnalyzer: MlKitAnalyzer, val executor: Executor, barcodeScanner: BarcodeScanner
) : ImageAnalysis.Analyzer by mlKitAnalyzer, LifecycleObserver by barcodeScanner {
}
````
and later scanning started via:
````kotlin
cameraController.setImageAnalysisAnalyzer(analyzer.executor, analyzer)
````
No scanning is happening (consumer is never called back).
However when I change the delegation to the direct inheritance of the `MlKitAnalyzer` - then scanning works as expected:
````kotlin
class BarcodeScanningAnalyzer internal constructor(
barcodeScanner: BarcodeScanner, val executor: Executor, consumer: Consumer
) : MlKitAnalyzer(
listOf(barcodeScanner),
/* provides ability drawing easily a overlay/box around the QR Code in real time */
COORDINATE_SYSTEM_VIEW_REFERENCED,
executor,
consumer
), LifecycleObserver by barcodeScanner
````
**SDK Info:**
- SDK Name & Version: com.google.mlkit:barcode-scanning:17.0.2
**Smartphone:**
- Device/Simulator: Pixel 9 Pro
- Device/Simulator OS: Android 15
**Development Environment:**
IDE: Android Studio Meerkat | 2024.3.1 Canary 4
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.