Skip to content

Camera plugin - Build failure due to missing symbol #74915

@svprdga

Description

@svprdga

Steps to Reproduce

  1. Create a new flutter project in the stable branch.
  2. Add as a dependency the camera plugin (https://pub.dev/packages/camera) version 0.7.0
  3. Add the sample code I have added and try to launch the app to view the camera preview

Expected results:

The camera preview starts successfully.

Actual results:

The app cannot be build (errors in the logs section).

Notes:

Version 0.6.4+5 works OK. The issue seems to be introduced in version 0.7.0.

Logs
/home/svprdga/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+1/android/src/main/java/io/flutter/plugins/camera/DeviceOrientationManager.java:194: error: cannot find symbol
    if (VERSION.SDK_INT >= VERSION_CODES.R) {
                                        ^
  symbol:   variable R
  location: class VERSION_CODES
/home/svprdga/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+1/android/src/main/java/io/flutter/plugins/camera/DeviceOrientationManager.java:195: error: cannot find symbol
      return activity.getDisplay();
                     ^
  symbol:   method getDisplay()
  location: variable activity of type Activity
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':camera:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
Exception: Gradle task assembleDebug failed with exit code 1
Analyzing super_qr_code_reader_flutter...                               
No issues found! (ran in 1.9s)

[✓] Flutter (Channel stable, 1.22.6, on Linux, locale en_US.UTF-8)
    • Flutter version 1.22.6 at /home/svprdga/snap/flutter/common/flutter
    • Framework revision 9b2d32b605 (6 days ago), 2021-01-22 14:36:39 -0800
    • Engine revision 2f0af37152
    • Dart version 2.10.5

 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /home/svprdga/Android/Sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /usr/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
    • All Android licenses accepted.

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] VS Code (version 1.52.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.18.1

[✓] Connected device (1 available)
    • SM A320FL (mobile) • 5203de294674c325 • android-arm • Android 8.0.0 (API 26)

! Doctor found issues in 1 category.

Sample app:

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:provider/provider.dart';
import 'package:super_qr_code_reader_flutter/presentation/scanner/scanner_bloc.dart';
import 'package:super_qr_code_reader_flutter/util/static_wrapper.dart';

class ScannerScreen extends StatefulWidget {
  ScannerScreen({Key key}) : super(key: key);

  @override
  _ScannerScreenState createState() => _ScannerScreenState();
}

class _ScannerScreenState extends State<ScannerScreen> {
  // ***************************** INJECTED VARS *************************** //

  StaticWrapper _static;

  // ********************************* VARS ******************************** //

  ScannerBloc _bloc;
  CameraController _cameraController;

  // ****************************** LIFECYCLE ****************************** //

  @override
  void initState() {
    super.initState();

    _static = Provider.of<StaticWrapper>(context, listen: false);

    _bloc = ScannerBloc();
  }

  @override
  void dispose() {
    _cameraController?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<ScannerBloc>.value(
        value: _bloc,
        child: Consumer<ScannerBloc>(builder: (context, bloc, child) {
          _bloc = bloc;

          return FutureBuilder<List<CameraDescription>>(
            future: availableCameras(),
            builder: (BuildContext context,
                AsyncSnapshot<List<CameraDescription>> snapshot) {
              Widget body;
              if (snapshot.hasData) {
                _initCameraController(snapshot.data);

                body = _cameraController.value.isInitialized
                    ? AspectRatio(
                        aspectRatio: _cameraController.value.aspectRatio,
                        child: CameraPreview(_cameraController),
                      )
                    : Container();
              } else {
                body = PlatformCircularProgressIndicator();
              }

              return PlatformScaffold(
                backgroundColor: Color(0x00FFFFFF),
                appBar: PlatformAppBar(
                  title: Text(_static.translate(context, 'app_name')),
                ),
                body: body,
              );
            },
          );
        }));
  }

  // *************************** PRIVATE METHODS *************************** //

  _initCameraController(List<CameraDescription> cameras) {
    if (_cameraController == null) {
      _cameraController = CameraController(cameras[0], ResolutionPreset.medium);
      _cameraController.initialize().then((_) {
        if (!mounted) {
          return;
        }
        setState(() {});
      });
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions