3

I am trying to use the camera plugin in flutter(for Image Picker from camera as the source) ,I understand that I need to have a min sdk version to 21 for using it,but when I see the error it also suggests that we can also override the plugin usage(which may result in runtime crashes)

 use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)

enter image description here so can anyone point me in the right direction on How do I override it ?

Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
  • what Image picker are you using? If it is third party plugin, why not just use the [official one](https://pub.dev/packages/image_picker)? – Harshvardhan Joshi Dec 30 '19 at 15:16
  • yes I am using the same official one image_picker v0.6.2+3 – Mahesh Jamdade Dec 30 '19 at 16:51
  • according to the source code of the official library. in [build.gradle](https://github.com/flutter/plugins/blob/master/packages/image_picker/android/build.gradle) `minSdk` is set to 16. – Harshvardhan Joshi Dec 31 '19 at 04:11
  • I am not sure what's causing this problem. Unless you are also using `camera` plugin by flutter as well. it has a `minSdk` set to 21. which means your project should also match those contraints. – Harshvardhan Joshi Dec 31 '19 at 04:12
  • I am able to use the camera plugin if I set the minsdk version to 21,I just wanted to know if its possible to override bumping up the min sdk to 21, I want my app to support min sdk 16 – Mahesh Jamdade Jan 01 '20 at 03:39
  • I don't think it's a good idea to override the plugin. Since the flutter team must always provide minimum SDK support as a platform and if they are not, it means there's no point. if you still modify the constraints then afterward you are on your own. Nobody else can help you. – Harshvardhan Joshi Jan 01 '20 at 04:06
  • I'd suggest creating your own camera plugin in flutter for such cases, it'll help you find a way out of this or at least allow you know if you should override it or not. – Harshvardhan Joshi Jan 01 '20 at 04:08
  • What is the flutter sdk version you use ?? – ElsayedDev Aug 25 '20 at 04:06

2 Answers2

0

Use

In AndroidManifest.xml

Also try to change Flutter SDK version to DEV if you use stable version.

Also check:

https://github.com/flutter/plugins/pull/1598/files

ElsayedDev
  • 601
  • 1
  • 8
  • 15
0

The camera plugin uses the camera2 API, which is only available in API level 21 and newer.

Overriding this error (with overrideTools) will break your app for apps on API level 20 and below.

If you're just curious about how tools:overrideLibrary is used, it is a AndroidManifest.xml attribute: Another stackOverflow question/ answer: How do I use tools:overrideLibrary in a build.gradle file?


If you need to support API levels 20 and below, you need to find an alternative to the Flutter camera plugin, because it uses the camera2 API. I wasn't able to find one, so you probably have to make your own. How to use Android's camera or camera2 API to support old and new API versions without deprecation notes?

Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167