【Flutter】Androidビルド時のエラー Error: uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library【解決方法】

はじめに

自分用のメモとして作成した記事のため説明が非常に荒くなっています。
ご了承ください。

現象

FlutterをAndroidエミュレータでビルドした際にエラーが発生し、以下のメッセージが表示されました。

/Users/hogehoge/FlutterProjects/projects_name/android/app/src/debug/AndroidManifest.xml Error:
	uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:cloud_firestore] /Users/hogehoge/FlutterProjects/projects_name/build/cloud_firestore/intermediates/merged_manifest/debug/AndroidManifest.xml as the library might be using APIs not available in 16
	Suggestion: use a compatible library with a minSdk of at most 16,
		or increase this project's minSdk version to at least 19,
		or use tools:overrideLibrary="io.flutter.plugins.firebase.firestore" to force usage (may lead to runtime failures)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:cloud_firestore] /Users/hogehoge/FlutterProjects/projects_name/build/cloud_firestore/intermediates/merged_manifest/debug/AndroidManifest.xml as the library might be using APIs not available in 16
  	Suggestion: use a compatible library with a minSdk of at most 16,
  		or increase this project's minSdk version to at least 19,
  		or use tools:overrideLibrary="io.flutter.plugins.firebase.firestore" to force usage (may lead to runtime failures)

* 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 1s
┌─ Flutter Fix ─────────────────────────────────────────────────────────────────────────────────┐
│ The plugin cloud_firestore requires a higher Android SDK version.                             │
│ Fix this issue by adding the following to the file                                            │
│ /Users/koborinainozomi/FlutterProjects/onayamijika/android/app/build.gradle:                  │
│ android {                                                                                     │
│   defaultConfig {                                                                             │
│     minSdkVersion 19                                                                          │
│   }                                                                                           │
│ }                                                                                             │
│                                                                                               │
│ Note that your app won't be available to users running Android SDKs below 19.                 │
│ Alternatively, try to find a version of this plugin that supports these lower versions of the │
│ Android SDK.                                                                                  │
│ For more information, see:                                                                    │
│ https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration                 │
└───────────────────────────────────────────────────────────────────────────────────────────────┘
Exception: Gradle task assembleDebug failed with exit code 1

原因

上記現象発生時のエラーメッセージを読むと、

minSdkVersionを19以上にしてね!

ということのようです。

対策

Android/App/build.gradleに対して以下のコードを1番下に追記します。

android {
  defaultConfig {                                                                            
    minSdkVersion 19
    multiDexEnabled true // multidexサポートライブラリを使用する
  }
}       

 

これだけでOKです!